Assume our requirement is to send email from sender@gmail.com to receiver@gmail.com. Here we are going to use the configuration settings of Gmail SMTP mail server. Click here to get the Details of Gmail SMTP Mail Server Configuration.
In your Project, include the following Namespaces;
using System.Net.Mail;
using System.Net;
Then include the below code within your Send email Method;
MailMessage mail = new MailMessage();
try{
NetworkCredential cred = new NetworkCredential(“sender”, “password”);
mail.To.Add(“receiver@gmail.com”);
mail.Subject = “Email Message Title”;
mail.From = new MailAddress(“sender@gmail.com”);
mail.IsBodyHtml = true;
mail.Body = “Email body Content here”;
SmtpClient smtp = new SmtpClient(“smtp.gmail.com”);
smtp.UseDefaultCredentials = false;
smtp.EnableSsl = true;
smtp.Credentials = cred;
smtp.Port = 587;
smtp.Send(mail);
}
catch (Exception ex){
}