.Net SMTPClient Send Through Gmail 

Tags:

To test a Mail application I’m working on, I decided to use GMail, but it wasn’t as easy as I’d hoped. Luckily, I found this code snippet on TechNet Forums that worked for me:

 

MailMessage msgMail = new MailMessage("?????@gmail.com", ??????@gmail.com, "subject", "message body");
SmtpClient smtp = new SmtpClient("smtp.gmail.com", 587);
smtp.EnableSsl = true;
smtp.DeliveryMethod = SmtpDeliveryMethod.Network;
smtp.Credentials = new System.Net.NetworkCredential("?????@gmail.com", "?????");
try
{
   smtp.Send(msgMail);
}
catch (Exception ex)
{
}

Just replace the question marks with your GMail credentials, and it should work for you too.

 
Posted by Tom Resing on 17-Oct-09
0 Comments  |  Trackback Url  |  Link to this post | Bookmark this post with:        
 

Comments

Name:
URL:
Email:
Comments: