System.Net.Mail FAQ

Complete FAQ Listing


3.2.3 How do I specify multiple recipients? Printer Friendly

Because the To, CC, and Bcc properties are MailAddress collections, to add additional recipients, all we need to do is call .Add(...) on the respective properties.

Below is an example that demonstrates adding multiple To, CC, and Bcc addresses.

[ C# ]

 static void MultipleRecipients()
{
//create the mail message
MailMessage mail = new MailMessage();

//set the addresses
//to specify a friendly 'from' name, we use a different ctor
mail.From = new MailAddress("me@mycompany.com", "Steve James");

//since the To,Cc, and Bcc accept addresses, we can use the same technique as the From address
//since the To, Cc, and Bcc properties are collections, to add multiple addreses, we simply call .Add(...) multple times
mail.To.Add("you@yourcompany.com");
mail.To.Add("you2@yourcompany.com");
mail.CC.Add("cc1@yourcompany.com");
mail.CC.Add("cc2@yourcompany.com");
mail.Bcc.Add("blindcc1@yourcompany.com");
mail.Bcc.Add("blindcc2@yourcompany.com");

//set the content
mail.Subject = "This is an email";
mail.Body = "this is the body content of the email.";

//send the message
SmtpClient smtp = new SmtpClient("127.0.0.1");
smtp.Send(mail);
}



[ VB.NET ]
 Sub MultipleRecipients()
'create the mail message
Dim mail As New MailMessage()

'set the addresses
'to specify a friendly 'from' name, we use a different ctor
mail.From = New MailAddress("me@mycompany.com", "Steve James")

'since the To,Cc, and Bcc accept addresses, we can use the same technique as the From address
'since the To, Cc, and Bcc properties are collections, to add multiple addreses, we simply call .Add(...) multple times
mail.To.Add("you@yourcompany.com")
mail.To.Add("you2@yourcompany.com")
mail.CC.Add("cc1@yourcompany.com")
mail.CC.Add("cc2@yourcompany.com")
mail.Bcc.Add("blindcc1@yourcompany.com")
mail.Bcc.Add("blindcc2@yourcompany.com")

'set the content
mail.Subject = "This is an email"
mail.Body = "this is the body content of the email."

'send the message
Dim smtp As New SmtpClient("127.0.0.1")
smtp.Send(mail)
End Sub 'MultipleRecipients