您的位置:首页 > 大数据 > 人工智能

MailBee.NET Objects发送电子邮件(SMTP)教程一:使用SMTP服务器发送消息

2017-04-27 16:05 771 查看
概述:该文主要介绍了MailBee.NET Objects中使用SMTP服务器发送消息的代码示例,Smtp对象提供了多种方法和属性来调整优化发送消息的过程。

MailBee.NET Objects介绍和试用点击查看>>>
 
Smtp对象提供了多种方法和属性来调整优化发送消息的过程。可以创建一个新的Smtp对象实例,如下所示:
C#:

Smtp mailer = new Smtp();

VB.NET:

Dim mailer As New Smtp()

 
如果SMTP服务器不需要任何身份验证,那么指定的主机名或它的IP地址就足以连接到此SMTP服务器。
C#:

mailer.SmtpServers.Add("mail.domain.com");

VB.NET:

mailer.SmtpServers.Add("mail.domain.com")

 
然而,大多数服务器现在要求用户对自己进行身份验证(例如,如果要通过此服务器将电子邮件发送给外部收件人,则必须拥有有效的帐户)。要指定你的帐户凭据,请使用以下代码:
C#:
mailer.SmtpServers.Add("mail.domain.com", "jdoe", "secret");

VB.NET:

mailer.SmtpServers.Add("mail.domain.com", "jdoe", "secret")

 
根据服务器设置,你可能需要输入整个电子邮件地址,而不仅仅是一个帐户名称(例如,在某些情况下为jdoe@domain.com或domain.com \ jdoe)。
某些SMTP服务器要求客户端进行身份验证,但不支持任何SMTP命令。这些服务器依赖于同一个客户端的最近POP3连接的认证结果(即相同的IP地址)。因为POP3和SMTP服务器通常共享相同的用户帐户数据库。
在发送消息之前,你应该确定内容。例如:
C#:

mailer.Message.From.AsString = "jdoe@domain.com";

mailer.Message.To.AsString = "bill@domain.com";

mailer.Message.Subject = "Hi";

mailer.Message.BodyPlainText = "Hello Bill";

mailer.Message.From.AsString = "John Doe ";

mailer.Message.To.AsString = "Bill  (Company Inc), Kathy ";

mailer.Message.Subject = "The document";

mailer.Message.BodyHtmlText = "The document body";

mailer.Message.From.Email = "jdoe@domain.com";

mailer.Message.From.DisplayName = "John Doe";

mailer.Message.To.AsString = "Kathy ";

mailer.Message.Cc.Add("bill@domain.com", "Bill Smith");

mailer.Message.Subject = "News";

mailer.Message.BodyPlainText = "News body";

 
VB.NET:

mailer.Message.From.AsString = "jdoe@domain.com"

mailer.Message.To.AsString = "bill@domain.com"

mailer.Message.Subject = "Hi"

mailer.Message.BodyPlainText = "Hello Bill"

mailer.Message.From.AsString = "John Doe "

mailer.Message.To.AsString = "Bill  (Company Inc), Kathy "

mailer.Message.Subject = "The document"

mailer.Message.BodyHtmlText = "The document body"

mailer.Message.From.Email = "jdoe@domain.com"

mailer.Message.From.DisplayName = "John Doe"

mailer.Message.To.AsString = "Kathy "

mailer.Message.Cc.Add("bill@domain.com", "Bill Smith")

mailer.Message.Subject = "News"

mailer.Message.BodyPlainText = "News body"

 
内容完成后,你就可以点击发送了。
C#:

mailer.Send();

VB.NET:

mailer.Send()
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
相关文章推荐