群发邮件是网站推广和网络营销的重要手段之一。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("群发成功!")