[Email] with Gmail

Send email with C# using gmail

This code is a very simple one that you can use to make your C# (Cs or C sharp) application send you an email from any gmail adress. Just make a new gmailadress for this purpose and you’re off!

Don’t use the GmailHelper library. It seems great, but i couldnt get it working on 2010 express since it had all kinds of old dependencies.
Sending email with c# is super easy, but it took me an hour to work it out, so as a note to myself and for your possibly convenience, we can use the following:

  1. declare
    using System.Net.Mail;

System.Net.Mail.MailMessage mail = new System.Net.Mail.MailMessage();
System.Net.NetworkCredential cred = new System.Net.NetworkCredential("ACCOUNT@gmail.com", "PASSWORD");
mail.Subject = "subj";
mail.From = new System.Net.Mail.MailAddress("ACCOUNT@gmail.com");
mail.IsBodyHtml = true;
mail.Body = "message";
System.Net.Mail.SmtpClient smtp = new System.Net.Mail.SmtpClient("smtp.gmail.com");
smtp.UseDefaultCredentials = false;
smtp.EnableSsl = true;
smtp.Credentials = cred;
smtp.Port = 587;


One response

24 03 2011
More code released « Tim Zaman

[…] [Email] with Gmail […]

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

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

Google+ photo

You are commenting using your Google+ 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 )

Connecting to %s

%d bloggers like this: