Sending email via GMail in C#/.NET using SmtpClient

I’ve stubbed my toe on this a couple of times, so here is the magic incantation:

using (SmtpClient smtp = new SmtpClient())
{
    smtp.DeliveryMethod = SmtpDeliveryMethod.Network;
    smtp.UseDefaultCredentials = false;
    smtp.EnableSsl = true;
    smtp.Host = "smtp.gmail.com";
    smtp.Port = 587; 
    smtp.Credentials = new NetworkCredential("email@gmail.com", "password");
    // send the email
}

Comments

I Thought He Came With You
Robert Ellison's blog.

Thank you Feedly

Blog Archives