.Net SMTPClient Send Through Gmail

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", "?????");
catch (Exception ex)

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

Leave a Reply