Monday, September 20, 2010

How to send email in asp.net using C# and smtp as gmail

using System.Net.Mail;

MailMessage mail = new MailMessage();
mail.From = new MailAddress("mailtesting22@gmail.com");
mail.To.Add(new MailAddress("receiver_id@gmail.com"));
mail.Subject = "Test mail";
mail.Body = "Hi! it is a simplemail testing";
mail.IsBodyHtml = true;
try
{
SmtpClient myclient = new SmtpClient();
myclient.Host = "smtp.gmail.com";
myclient.Port = 587;
myclient.Credentials = new
System.Net.NetworkCredential("mailtesting22@gmail.com", "password");
myclient.EnableSsl = true;
myclient.Send(mail);
}
catch(Exception ex)
{
Response.Write(ex.Message);
}

No comments:

Post a Comment