Spire.Email 教程2:如何在C#,VB.NET 中發送批量電子郵件

工具:Spire.Email for .NEThtml

代碼演示:工具

Step 1:建立MailMessage類的實例並指定發件人和收件人。htm

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:設置消息的主題和正文。對象

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

Step 3:初始化MailMessageCollection類的對象,並將MailMessage類的實例添加到對象中。ip

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

Step 4:使用主機,端口,用戶名和密碼建立SmtpClient實例,並使用SendSome方法發送批量的電子郵件。ci

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");

完整代碼:get

[C#]it

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]io

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")

慧都控件網cli

相關文章
相關標籤/搜索