tags:

views:

387

answers:

1

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?

+1  A: 

The MailMessage class wants to protect it's properties, that's proper Encapsulation.

Your task would have been a little easier if it had supported a AddRange method but as it stands your code is about as easy as it's going to get.

Henk Holterman
Yeah, AddRange would have been ideal... oh well, I guess it's not the end of the world!
Town