Send email to multiple recipients

In this post we’ll show how to send email message to multiple recipients.

If your email should look differently for each recipient (customized “Hello [FirstName] [LastName]” message) take a look at:

If your email looks exactly the same for each recipient the easiest way is to use BCC field (Blind-Carbon-Copy), and specify Undisclosed recipients group as the message recipient:

MailBuilder builder = new MailBuilder();
builder.From.Add(new MailBox("alice@example.com", "Alice"));

builder.To.Add(new MailGroup("Undisclosed recipients"));

builder.Bcc.Add(new MailBox("bob@example.com", "Bob"));
builder.Bcc.Add(new MailBox("tom@example.com", "Tom"));
builder.Bcc.Add(new MailBox("john@example.com", "John"));

Here’s entire sample, that creates email message, connects to SMTP server and sends the message:

// C# version

MailBuilder builder = new MailBuilder();
builder.From.Add(new MailBox("alice@example.com", "Alice"));

builder.To.Add(new MailGroup("Undisclosed recipients"));

builder.Bcc.Add(new MailBox("bob@example.com", "Bob"));
builder.Bcc.Add(new MailBox("tom@example.com", "Tom"));
builder.Bcc.Add(new MailBox("john@example.com", "John"));

builder.Subject = "Put subject here";
builder.Html = "Put <strong>HTML</strong> message here.";

// Plain text is automatically generated, but you can change it:
//builder.Text = "Put plain text message here.";

IMail email = builder.Create();

// Send the message
using (Smtp smtp = new Smtp())
{
    smtp.Connect("server.example.com");   // or ConnectSSL for SSL
    smtp.UseBestLogin("user", "password"); // remove if not needed

    smtp.SendMessage(email);

    smtp.Close();
}
' VB.NET version

Dim builder As New MailBuilder()
builder.From.Add(New MailBox("alice@example.com", "Alice"))
builder.[To].Add(New MailGroup("Undisclosed recipients"))

builder.Bcc.Add(New MailBox("bob@example.com", "Bob"))
builder.Bcc.Add(New MailBox("tom@example.com", "Tom"))
builder.Bcc.Add(New MailBox("john@example.com", "John"))

builder.Subject = "Put subject here"
builder.Htm = "Put <strong>HTML</strong> message here."

' Plain text is automatically generated, but you can change it:
'builder.Text ="Put plain text message here."

Dim email As IMail = builder.Create()

' Send the message
Using smtp As New Smtp()
	smtp.Connect("server.example.com")    ' or ConnectSSL for SSL
	smtp.UseBestLogin("user", "password")  ' remove if not needed

	smtp.SendMessage(email)

	smtp.Close()
End Using

Tags:  

Questions?

Consider using our Q&A forum for asking questions.