彩票走势图

Spire.Email 教程:如何在C#,VB.NET 中发送批量电子邮件

原创|使用教程|编辑:王香|2017-07-18 10:39:06.000|阅读 386 次

概述:Spire.Email 是一款专业且独立的电子邮件组件,今天的教程将给大家介绍在保证安全性和隐私性的前提下,如何通过Spire.Email 发送批量邮件给不同的收件人。

# 慧都年终大促·界面/图表报表/文档/IDE等千款热门软控件火热促销中 >>

相关链接:

工具:Spire.Email for .NET

代码演示:

Step 1:创建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");

Step 2:设置消息的主题和正文。

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

Step 3:初始化MailMessageCollection类的对象,并将MailMessage类的实例添加到对象中。

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

Step 4:使用主机,端口,用户名和密码创建SmtpClient实例,并使用SendSome方法发送批量的电子邮件。

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

完整代码:

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

慧都控件网

热门格式转换工具在线订购特惠中点击查看>>>>


图片1

标签:电子邮件

本站文章除注明转载外,均为本站原创或翻译。欢迎任何形式的转载,但请务必注明出处、不得修改原文相关链接,如果存在内容上的异议请邮件反馈至chenjj@capbkgr.cn


为你推荐

  • 推荐视频
  • 推荐活动
  • 推荐产品
  • 推荐文章
  • 慧都慧问
扫码咨询


添加微信 立即咨询

电话咨询

客服热线
023-68661681

TOP