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 www.codeproject.com
//Builed The MSG
System.Net.Mail.MailMessage msg = new System.Net.Mail.MailMessage();
msg.To.Add("reciver@gmail.com");
msg.To.Add("another.reciver@yahoo.com");
msg.From = new MailAddress("dummy@gmail.com", "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("dummy@gmail.com", "SecretPass");
client.Port = 587;//or use 587
client.Host = "smtp.gmail.com";
client.EnableSsl = true;
client.SendCompleted += new SendCompletedEventHandler(client_SendCompleted);
object userState=msg;
try
{
//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: