The Problem Solver

Tell me and I will forget
Show me and I will remember
Involve me and I will understand
- Confucius -

Google Ads

This Blog

Syndication

Search

Tags

News





  • View Maurice De Beijer's profile on LinkedIn

Community

Email Notifications

Explore

Archives

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 Smile

 

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 = "smtp.gmail.com";
var client = new SmtpClient(host, 587);
client.EnableSsl = true;
client.Credentials = new NetworkCredential("<<your username>>", "<<your password>>");
client.Send(message);

 

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.

 

Enjoy!

www.TheProblemSolver.nl
Wiki.WindowsWorkflowFoundation.eu

Published Wed, Nov 11 2009 20:24 by Maurice
Filed under: ,