AspBucket offers ASP.NET, C#, VB, Jquery, CSS, Ajax, SQL tutorials. It is the best place for programmers to learn

Friday, 30 October 2015

Send Mail by gmail account in ASP.NET

You can integrate mail via gmail account but make sure that gmail settings allow less secure app. Click on Gmail settings & allow less secure app (gmail->Setttings->allow less secure app)




MailMessage mail = new MailMessage();
mail.From = new MailAddress("xyz@gmail.com");
mail.Sender = new MailAddress("xyz@gmail.com");
mail.To.Add("external@emailaddress");
mail.IsBodyHtml = true;
mail.Subject = "Email Sent";
mail.Body = "Body content from";
SmtpClient smtp = new SmtpClient("smtp.gmail.com", 587);
smtp.UseDefaultCredentials = false;
smtp.Credentials = new System.Net.NetworkCredential("xyz@gmail.com", "your_password");
smtp.DeliveryMethod = SmtpDeliveryMethod.Network;
smtp.EnableSsl = true;
smtp.Timeout = 30000;
try
{
     smtp.Send(mail);
}
catch (SmtpException e)
{
    textBox1.Text= e.Message;
}

0 comments :

Post a Comment

  • Popular Posts
  • Comments