Sending mail messages through Gmail

recently I had to send a bunch of identical email messages for the CodeCamp we are organizing. Now there are plenty of ways to do this but I decided to write a little program using C# to send them. And just to make sure I can find the code next year [:)]


var from = new MailAddress("<<your email>>", "<<your name??");

var to = new MailAddress("<<destination address>>", "<<their name>>");

var message = new MailMessage(from, to);

message.Subject = "The subject";

message.Body = "The message body";

message.IsBodyHtml = true;


var host = "";

var client = new SmtpClient(host, 587);

client.EnableSsl = true;

client.Credentials = new NetworkCredential("<<your username>>", "<<your password>>");



Easy as that.

Few things to note. I used a different sender address as we wanted all replies to end up in a shared mailbox instead of mine. Worked just fine even though I used my own account details to send.

There is a check on the number of messages send in a short time span. Not sure what the limit is, it seemed something like 100 per minute, but I had to add some sleep time between messages in order to send them all. No big deal but something to keep in mind.





Leave a Reply

Your email address will not be published. Required fields are marked *