群发邮件是网站推广和网络营销的重要手段之一。Spire.Email支持通过POP3、IMAP和SMTP协议收发邮件,本文将以SMTP为例介绍如何群发邮件。
C#
//实例化三个MailMessage对象,指定发件人邮箱和接收者的邮箱地址
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 = "标题";
message1.BodyText = message2.BodyText = message3.BodyText= "内容";
//创建一个以MailMessage为对象的List
List msgs = new List();
//添加MailMessage对象到List
msgs.Add(message1);
msgs.Add(message2);
msgs.Add(message3);
//实例化SmtapClient对像
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.ConnectionProtocols = ConnectionProtocols.Ssl;
//使用SendSome方法发送List中的邮件
client.SendSome(msgs);
Console.WriteLine("群发成功!");
VB.NET
'实例化三个MailMessage对象,指定发件人邮箱和接收者的邮箱地址
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, "标题"))
message1.BodyText = InlineAssignHelper(message2.BodyText, InlineAssignHelper(message3.BodyText, "内容"))
'创建一个以MailMessage为对象的List
Dim msgs As New List()
'添加MailMessage对象到List
msgs.Add(message1)
msgs.Add(message2)
msgs.Add(message3)
'实例化SmtapClient对像
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.ConnectionProtocols = ConnectionProtocols.Ssl
'使用SendSome方法发送List中的邮件
client.SendSome(msgs)
Console.WriteLine("群发成功!")