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("sender@e-iceblue.com", "recipient1@e-iceblue.com"); MailMessage message2 = new MailMessage("sender@e-iceblue.com", " recipient2@e-iceblue.com"); MailMessage message3 = new MailMessage("sender@e-iceblue.com", " recipient3@e-iceblue.com");
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 = "sender@e-iceblue.com"; client.Password = "password"; client.ConnectionProtocols = ConnectionProtocols.Ssl; client.SendSome(msgs); Console.WriteLine("Message sent");
Full Code:
[C#]
MailMessage message1 = new MailMessage("sender@e-iceblue.com", "recipient1@e-iceblue.com"); MailMessage message2 = new MailMessage("sender@e-iceblue.com", " recipient2@e-iceblue.com"); MailMessage message3 = new MailMessage("sender@e-iceblue.com", " recipient3@e-iceblue.com"); 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 = "sender@e-iceblue.com"; client.Password = "password"; client.ConnectionProtocols = ConnectionProtocols.Ssl; client.SendSome(msgs); Console.WriteLine("Message sent");
[VB.NET]
Dim message1 As New MailMessage("sender@e-iceblue.com", "recipient1@e-iceblue.com") Dim message2 As New MailMessage("sender@e-iceblue.com", " recipient2@e-iceblue.com") Dim message3 As New MailMessage("sender@e-iceblue.com", " recipient3@e-iceblue.com") 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 = "sender@e-iceblue.com" client.Password = "password" client.ConnectionProtocols = ConnectionProtocols.Ssl client.SendSome(msgs) Console.WriteLine("Message sent")