Send Bulk Emails in C#, VB.NET

Send Bulk Emails in C#, VB.NET

2017-07-12 06:24:20 Written by  Koohji
Rate this item
(0 votes)

Sending bulk emails means that you can send a batch of emails to multiple recipients and they will not be able to determine the others you've sent the message to.

The following code snippets demonstrate how to send bulk emails using Spire.Email in C# and VB.NET.

Step 1: Create instances of MailMessage class and specify sender and recipients.

MailMessage message1 = new MailMessage("[email protected]", "[email protected]");
MailMessage message2 = new MailMessage("[email protected]", " [email protected]");
MailMessage message3 = new MailMessage("[email protected]", " [email protected]");

Step 2: Set the subject and body text of the messages.

message1.Subject = message2.Subject = message3.Subject = "Subject";
message1.BodyText = message2.BodyText = message3.BodyText = "This is body text.";

Step 3: Initialize an object of MailMessageCollection class and add the instances of MailMessage class into the object.

List msgs = new List();
msgs.Add(message1);
msgs.Add(message2);
msgs.Add(message3);

Step 4: Create a SmtpClient instance with host, port, username and password, and send batch of emails using SendSome method.

SmtpClient client = new SmtpClient();
client.Host = "smtp.outlook.com";
client.Port = 587;
client.Username = "[email protected]";
client.Password = "password";
client.ConnectionProtocols = ConnectionProtocols.Ssl;
client.SendSome(msgs);
Console.WriteLine("Message sent");

Full Code:

[C#]
MailMessage message1 = new MailMessage("[email protected]", "[email protected]");
MailMessage message2 = new MailMessage("[email protected]", " [email protected]");
MailMessage message3 = new MailMessage("[email protected]", " [email protected]");
message1.Subject = message2.Subject = message3.Subject = "subject";
message1.BodyText = message2.BodyText = message3.BodyText = "This is body text.";

List msgs = new List();
msgs.Add(message1);
msgs.Add(message2);
msgs.Add(message3);

SmtpClient client = new SmtpClient();
client.Host = "smtp.outlook.com";
client.Port = 587;
client.Username = "[email protected]";
client.Password = "password";
client.ConnectionProtocols = ConnectionProtocols.Ssl;
client.SendSome(msgs);
Console.WriteLine("Message sent");
[VB.NET]
Dim message1 As New MailMessage("[email protected]", "[email protected]")
Dim message2 As New MailMessage("[email protected]", " [email protected]")
Dim message3 As New MailMessage("[email protected]", " [email protected]")
message1.Subject = InlineAssignHelper(message2.Subject, InlineAssignHelper(message3.Subject, "subject"))
message1.BodyText = InlineAssignHelper(message2.BodyText, InlineAssignHelper(message3.BodyText, "This is body text."))

Dim msgs As New List(Of MailMessage)()
msgs.Add(message1)
msgs.Add(message2)
msgs.Add(message3)

Dim client As New SmtpClient()
client.Host = "smtp.outlook.com"
client.Port = 587
client.Username = "[email protected]"
client.Password = "password"
client.ConnectionProtocols = ConnectionProtocols.Ssl
client.SendSome(msgs)
Console.WriteLine("Message sent")

Additional Info

  • tutorial_title:
Last modified on Wednesday, 15 September 2021 03:30