Wednesday 2 May 2012

Send Mail From Gmail in C#

Write this small code for sending e-Mail from your Gmail account

System.Net.Mail.MailMessage mail = new System.Net.Mail.MailMessage();
mail.To.Add("Destination Mail Address");
mail.From = new MailAddress("UserName", "One and only",
mail.Subject = "This is a test mail again";
mail.SubjectEncoding = System.Text.Encoding.UTF8;
mail.Body = "body Of Message";
mail.BodyEncoding = System.Text.Encoding.UTF8;
mail.IsBodyHtml = true;
mail.Priority = MailPriority.High;
SmtpClient client = new SmtpClient();
client.Credentials = new System.Net.NetworkCredential("UserName",
client.Port = 587;  // Gmail works on this port
client.Host = "";
client.EnableSsl = true;

No comments:

Post a Comment