How do I make a MailMessage with multiple recipients?

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

System.Net.Mail.MailMessage has a constructor that takes two string
parameters (from and to). To is described as:

"A String that contains the addresses of the recipients of the e-mail
message."

But when I put a list of recipients as the to I get the error:
"The specified string is not in the form required for an e-mail address."

I'm using the form "(e-mail address removed);[email protected]" which the earlier
(System.Web) object handled properly.

I've looked all over the help and gotten nowhere, none of the examples use
multiple recipients. Plus I don't see that I could build a
MailAddressCollection to give to the MailMessage, because no constructor
takes one and the To property is read-only.

Come to think of it, why have a parameterless constructor and not allow the
From and To to be set?

So... How do I make a MailMessage with multiple recipients?
 
OK, the work-around is:

System.Net.Mail.MailMessage msg = new
System.Net.Mail.MailMessage() ;

msg.From = new System.Net.Mail.MailAddress ( Sender ) ;

string[] addresses = Recipient.Split ( new char[] { ';' } ) ;
foreach ( string recip in addresses )
{
msg.To.Add ( recip );
}

But that wouldn't be necessary if the class matched the documentation.
 
Well OK, but the documentation should say so, especially as it's a change
from the earlier behaviour.
 
Back
Top