Sending E-Mail with .Net and GMail

This was so easy I just had to share.


// Create MailMessage Object
MailMessage Msg = new MailMessage(email,"natthompson@natthompson.com",subject,message);
// Setup SmtpClient to point to GMail SMTP server
SmtpClient client = new SmtpClient("smtp.gmail.com",587);
// set your credentials
client.Credentials = new System.Net.NetworkCredential("<SOMEEMAILADDRESS>@gmail.com", "XXXXXXX");
// turn on SSL
client.EnableSsl = true;
// send it!
client.Send(Msg);

Leave a Reply