I've got a MailAddressCollection that contains all the addresses I want to send an email to, but instead of being able to simply have:
myMessage.To = myMailAddressCollection;
I have to do:
foreach (MailAddress address in myMailAddressCollection)
{
myMessage.To.Add(address);
}
Can anyone shed any light on why the class is configured like that? Am I missing some other way of being able to assign to the To, CC or Bcc properties?
To add a CC recipient to an email message, create a MailAddress for the recipient's address and then add that object to the collection returned by the CC property.
Instances of the MailMessage class are used to construct email messages that are transmitted to an SMTP server for delivery using the SmtpClient class. The sender, recipient, subject, and body of an email message may be specified as parameters when a MailMessage is used to initialize a MailMessage object.
Allows applications to send email by using the Simple Mail Transfer Protocol (SMTP). The SmtpClient type is obsolete on some platforms and not recommended on others; for more information, see the Remarks section.
I know this is old but in case someone else stumbles across it:
MailAddressCollection.Add can accept a comma delimited string of email addresses. MailAddressCollection.ToString Method returns a comma delimited string of the contained email addresses.
So the OP could have done this:
myMessage.To.Add(myMailAddressCollection.ToString());
An AddRange method would still be preferred.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With