Class MailAddressCollection
Contents
[
Hide
]MailAddressCollection class
A list of e-mail addresses, such as the recipients of a message.
public class MailAddressCollection : Collection<MailAddress>
Constructors
| Name | Description |
|---|---|
| MailAddressCollection() | The default constructor. |
Methods
| Name | Description |
|---|---|
| Add(MailAddress) | Adds an address to the collection. |
| Add(string) | Adds one or more addresses to the collection. |
| AddRange(IEnumerable<MailAddress>) | Adds a sequence of addresses. |
| AddRange(MailAddressCollection) | Adds the addresses of another collection. |
| Copy() | Creates a copy of the collection. |
| override ToString() | Returns the addresses as a comma-separated list, as written in a header. |
| implicit operator | Performs an implicit conversion from MailAddress to MailAddressCollection. (2 operators) |
Remarks
A string converts to this class implicitly, so msg.To = "a@example.com, b@example.com"; works.
Examples
This example adds recipients to a message in several ways.
[C#]
var msg = new MailMessage();
msg.From = new MailAddress("sender@example.com", "Sender");
// a comma-separated list
msg.To.Add("alice@example.com, bob@example.com");
// one address with a display name
msg.CC.Add(new MailAddress("carol@example.com", "Carol"));
// implicit conversion from a string
msg.Bcc = "audit@example.com";
foreach (MailAddress address in msg.To)
{
Console.WriteLine(address.Address);
}
[Visual Basic]
Dim msg = New MailMessage()
msg.From = New MailAddress("sender@example.com", "Sender")
' a comma-separated list
msg.To.Add("alice@example.com, bob@example.com")
' one address with a display name
msg.CC.Add(New MailAddress("carol@example.com", "Carol"))
' implicit conversion from a string
msg.Bcc = "audit@example.com"
For Each address As MailAddress In msg.To
Console.WriteLine(address.Address)
Next
See Also
- class MailAddress
- namespace Aspose.Email
- assembly Aspose.Email