Saturday, August 3, 2013

Multiple recipients with SmtpClient in .NET

When sending a quick email, for example to notify of a PowerShell task failure, the simplest System.Net.Mail.SmtpClient method to use is usually this one:
public void Send(
string from,
string recipients,
string subject,
string body
)

The parameter name recipients implies that it is possible to send the email to more than one recipient - but the documentation does not say how. I tried separating the addresses with a semicolon, but that failed with the following error:
"Send" with "4" argument(s): "An invalid character was found in the mail header: ';'."
The correct separator to use, which I only found out by trawling through the .NET source with ILSpy, is a comma (,).

0 comments:

Post a Comment