MailBee.NET Objects是一款为建立、发送、接收以及处理电子邮件而设计的健壮、功能丰富的.NET控件。几行代码即可为应用程序添加E-Mail支持,简单高效。具有“必需”以及独特的功能,这些控件帮助开发人员简单快速地将复杂的电子邮件功能添加到他们的应用程序中。服务器
本文主要介绍了电子邮件请求阅读/发送状态提示的代码示例。要查看邮件发送状态,开发人员应使用DeliveryNotificationOptions类。此类提供如何以及什么时候将ESMTP传递状态通知(DSN)发送回发送方的属性和方法。要获取或设置触发ESMTP服务器的事件,开发人员应使用NotifyCondition属性:dom
C# Smtp mailer = new Smtp(); mailer.DeliveryNotification.NotifyCondition = DsnNotifyCondition.Always; VB.NET Dim mailer As New Smtp() mailer.DeliveryNotification.NotifyCondition = DsnNotifyCondition.Always
若是邮件服务器支持DSN扩展,则开发人员能够指定触发ESMTP服务器将发送状态发回邮件发送方的事件。为此开发人员应该使用DsnNotifyCondition枚举。例如,使用默认值,服务器将自行发送通知;若是邮件发送失败则会触发通知。有时,当邮件发送失败时,可使用发送状态通知返回原始邮件。使用MailBee,开发人员能够指定邮件发送失败时哪一个部分(整个邮件或仅标头)应与发送状态通知一块儿发回:设计
C# mailer.DeliveryNotification.ReturnPortion = DsnReturnPortion.Header; VB.NET mailer.DeliveryNotification.ReturnPortion = DsnReturnPortion.Header
开发人员还能够指定将添加到通知邮件中的特定惟一字符串。它能够用于将通知邮件与原始邮件进行匹配:code
C# mailer.DeliveryNotification.TrackingID = "UNQIUE_STRING_q8sdf74d"; VB.NET mailer.DeliveryNotification.TrackingID = "UNQIUE_STRING_q8sdf74d"
若是服务器不支持DSN,则不会发送状态通知。可是,在这种状况下,不会向应用程序返回任何错误。你能够手动检
查服务器是否支持发送状态通知:事件
C# if (mailer.GetExtension("DSN") != null) { Console.WriteLine("The message will be submitted with DSN support"); } else { Console.WriteLine("The message will be submitted without DSN support"); } VB.NET If mailer.GetExtension("DSN") IsNot Nothing Then Console.WriteLine("The message will be submitted with DSN support") Else Console.WriteLine("The message will be submitted without DSN support") End If
请注意,你应该在Smtp.Connect方法调用后在调用GetExtension(“DSN”)。
请求查看邮件发送状态的另外一种方法是使用MailMessage.ConfirmReceipt属性。它容许开发人员获取或设置应收到发送确认邮件的我的电子邮件地址。
如下代码设置Return-Receipt-To消息头:ip
C# // Create new MailMessage object. MailMessage msg = new MailMessage(); msg.LoadMessage(@"C:\Temp\MyMail.eml"); msg.ConfirmReceipt = "jdoe@domain.com"; VB.NET ' Create new MailMessage object. Dim msg As New MailMessage() msg.LoadMessage("C:\Temp\MyMail.eml") msg.ConfirmReceipt = "jdoe@domain.com"
收件人的邮件服务器应该检查接收到的邮件Return-Receipt-To标题值,并将发送确认邮件发送到该标题中指定的电子邮件地址。所以,收件人的邮件软件必须支持Return-Receipt-To功能。一些服务器支持Return-Receipt-To和DSN,而其余服务器只支持其中一个,甚至不支持。你能够同时使用这两种方法。
发送状态信息还没有确保收件人已阅读该邮件。要获取包含电子邮件地址的字符串,请使用MailMessage.ConfirmRead属性。ci
C# // Create new MailMessage object. MailMessage msg = new MailMessage(); // Load the message from .eml file msg.LoadMessage(@"C:\Temp\MyMail.eml"); // Show the e-mail address of recipient of the read confirmation message. Console.WriteLine("Send confirmation to " + msg.ConfirmRead); VB.NET ' Create new MailMessage object. Dim msg As New MailMessage() ' Load the message from .eml file msg.LoadMessage("C:\Temp\MyMail.eml") ' Show the e-mail address of recipient of the read confirmation message. Console.WriteLine("Send confirmation to " + msg.ConfirmRead)
注意: 收件人使用的邮件客户端必须支持ConfirmRead功能(该软件必须支持Disposition-Notification-To标头)。开发