This blog is a knowledge base...where I clip cool tricks and urls

How to send email using Gmail SMTP - .NET 2.0

Read this article from code project.
clipped from
//Builed The MSG
System.Net.Mail.MailMessage msg = new System.Net.Mail.MailMessage();
msg.From = new MailAddress("", "One Ghost",System.Text.Encoding.UTF8);
msg.Subject = "Test mail using .net2.0";
msg.SubjectEncoding = System.Text.Encoding.UTF8;
msg.Body = "This is my msg Body";
msg.BodyEncoding = System.Text.Encoding.UTF8;
msg.IsBodyHtml = false;
msg.Priority = MailPriority.High;
//Add the Creddentials
SmtpClient client = new SmtpClient();
client.Credentials = new System.Net.NetworkCredential("", "SecretPass");
client.Port = 587;//or use 587
client.Host = "";
client.EnableSsl = true;
client.SendCompleted += new SendCompletedEventHandler(client_SendCompleted);
object userState=msg;
//you can also call client.Send(msg)
client.SendAsync(msg, userState);
catch (System.Net.Mail.SmtpException ex)
MessageBox.Show(ex.Message, "Send Mail Error");
 blog it

No comments: