Gửi mail từ dot NET qua Gmail


MailMessage mailMsg = new MailMessage();
mailMsg.From = new MailAddress("username@gmail.com");
mailMsg.To.Add(sTo);
mailMsg.ReplyTo = new MailAddress("new_username@gurucore.com", "reply to guru");
mailMsg.Subject = "subject of the mail";
mailMsg.IsBodyHtml = true;
mailMsg.BodyEncoding = Encoding.UTF8;
mailMsg.Body = "this is body, format is html <strong>hTML</strong>";
mailMsg.Priority = MailPriority.Normal;
// Smtp configuration
SmtpClient client = new SmtpClient();
client.Credentials = new NetworkCredential("username@gmail.com", "password");
client.Port = 587; //or use 465
client.Host = "smtp.gmail.com";
client.EnableSsl = true;
try
{
client.Send(mailMsg);
}
catch (SmtpException ex)
{
Literal1.Text = ex.Message + ex.StackTrace;
}

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s