MailBee.NET Objects撰写邮件教程(三):请求阅读/发送状态提示

来源:互联网 发布:三维设计软件 编辑:程序博客网 时间:2024/06/06 09:34
MailBee.NET Objects是一款为创建、发送、接收以及处理电子邮件而设计的健壮、功能丰富的.NET控件。几行代码便可为应用程序添加E-Mail支持,简单高效。具备“必需”以及独特的功能,这些控件帮助开发人员简单快速地将复杂的电子邮件功能添加到他们的应用程序中。
 
MailBee.NET Objects介绍和试用点击查看>>>
 
本文主要介绍了电子邮件请求阅读/发送状态提示的代码示例。目前MailBee.NET Objects在线订购享75折优惠正在进行中,欢迎您下载试用版进行运用!
要查看邮件发送状态,开发人员应使用DeliveryNotificationOptions类。此类提供如何以及何时将ESMTP传递状态通知(DSN)发送回发送方的属性和方法。要获取或设置触发ESMTP服务器的事件,开发人员应使用NotifyCondition属性:
C#Smtp mailer = new Smtp();mailer.DeliveryNotification.NotifyCondition = DsnNotifyCondition.Always;VB.NETDim mailer As New Smtp() mailer.DeliveryNotification.NotifyCondition = DsnNotifyCondition.Always
 
如果邮件服务器支持DSN扩展,则开发人员可以指定触发ESMTP服务器将发送状态发回邮件发送方的事件。为此开发人员应该使用DsnNotifyCondition枚举。例如,使用默认值,服务器将自行发送通知;如果邮件发送失败则会触发通知。有时,当邮件发送失败时,可以使用发送状态通知返回原始邮件。使用MailBee,开发人员可以指定邮件发送失败时哪个部分(整个邮件或仅标头)应与发送状态通知一起发回:
C#mailer.DeliveryNotification.ReturnPortion = DsnReturnPortion.Header;VB.NETmailer.DeliveryNotification.ReturnPortion = DsnReturnPortion.Header
 
开发人员还可以指定将添加到通知邮件中的特定唯一字符串。它可以用于将通知邮件与原始邮件进行匹配:
C#mailer.DeliveryNotification.TrackingID = "UNQIUE_STRING_q8sdf74d";VB.NETmailer.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.NETIf 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消息头:
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属性。
C#// Create new MailMessage object.MailMessage msg = new MailMessage();// Load the message from .eml filemsg.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 filemsg.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标头)。
阅读全文
0 0
原创粉丝点击