Wednesday, May 10, 2006

Recipient List in SmtpClient

Sometimes, which is more than frequently, I find huge holes in documentation for software products. I am no one to judge, since the documentation for my own software document has had its issues in the past, but when a product has an install based of hundreds of thousands, I would expect a little more.

 

Today’s exercise in futility is brought to you by Microsoft. I really do like Microsoft, but I like being sarcastic, too, so please forgive my negative vibes.

 

Anyway, the situation is this: I’m using System.Net.Mail.SmtpClient to send an email from an automated process whenever there is a machine failure on one of the big machines that my software interfaces with. SmtpClient is very cool. It is very powerful. With these three lines of code, I was shipping off emails to all my friends and family at a rather steady pace:

 

SmtpClient smtp = new SmtpClient(mymailserver, mymailserverport);

smtp.Credentials = new System.Net.NetworkCredential(myusername,

     mypassword);

smtp.Send("blah@blahblah.com", tothesepeople),

     mySubject, myError);

 

 

The problem was this: what do I use for a delimiter for the second parameter tothesepeople (the recipients) in the SmtpClient.Send function? You can find the documentation for that function here. Read it twice. It doesn’t say whether you should use a semi-colon, a space, or a bunch of carats. But have no fear, I figured it out rather quickly and I am here to provide you the answer, completely free of charge.

 

As is obvious to the most casual of observers, the answer is… ding, ding, ding, the COMMA! On a US keyboard, it is to the right of the M and below the <.

 

So rather than the standard format of Outlook, which is myfriend@hisdomain.com;myotherfriend@herdomain.com

 

You need to use:

myfriend@hisdomain.com,myotherfriend@herdomain.com

 

No comments: