Please try this
private void MailSendThruGmail()
{
MailAddress fromAddress = new MailAddress("sender@gmail.com", "From Name");
MailAddress toAddress = new MailAddress("recipient@gmail.com", "To Name");
const string subject = "test";
const string body = @"Using this feature, you can send an e-mail message from an application very easily.";
System.Net.Mail.MailMessage msg = new System.Net.Mail.MailMessage(fromAddress.Address, toAddress.Address, subject, body);
msg.IsBodyHtml = true;
var client = new SmtpClient("smtp.gmail.com", 587)
{
Credentials = new NetworkCredential("username", "password"),
EnableSsl = true
};
try
{
client.Send(msg);
}
catch (Exception ex)
{
Console.WriteLine(ex.ToString());
}
}