MailBee. NET Objects Tutorials

Request read/delivery receipt

To request the delivery confirmation, the developer should use DeliveryNotificationOptions class. This class provides properties and methods which control how and when ESMTP delivery status notifications (DSN) are sent back to the sender.

To get or set the events that trigger ESMTP server to send delivery status notification back to the sender of the message, the developer should use NotifyCondition property:

C#

Smtp mailer = new Smtp();
mailer.DeliveryNotification.NotifyCondition = DsnNotifyCondition.Always;

VB.NET

Dim mailer As New Smtp() 
mailer.DeliveryNotification.NotifyCondition = DsnNotifyCondition.Always

If the mail server supports DSN extension, the developer can specify events that trigger ESMTP server to send delivery status notification back to the sender of the message. For these purposes the developer should use DsnNotifyCondition enumeration. For example, with Default value, the server will send notification at its discretion; Failure triggers notification if the message delivery fails. Sometimes it can be useful to get the original message returned with the delivery status notification when the message delivery fails. With MailBee, the developer can specify which part of the message (the entire message or just the header) should be sent back with the delivery status notification when the message delivery fails:

C#

mailer.DeliveryNotification.ReturnPortion = DsnReturnPortion.Header;

VB.NET

mailer.DeliveryNotification.ReturnPortion = DsnReturnPortion.Header

The developer can also specify a certain unique string which will be added to the notification messages. It can be used to match the notification message with the original message:

C#

mailer.DeliveryNotification.TrackingID = "UNQIUE_STRING_q8sdf74d";

VB.NET

mailer.DeliveryNotification.TrackingID = "UNQIUE_STRING_q8sdf74d"

Status notifications will not be sent if server does not support DSN. However, no error is returned to the application in this case. You can manually check whether the server supports delivery status notifications:

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

Please note, you should call GetExtension("DSN") AFTER Smtp.Connect method call.

The alternative approach of requesting delivery receipt is using MailMessage.ConfirmReceipt property. It allows the developer to get or set the e-mail address of a person or an entity which should receive the delivery confirmation message.

The following code sets Return-Receipt-To message header:

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"

The mail server of the recipient should examine Return-Receipt-To header value of the received message and send the delivery confirmation message to the e-mail address specified in that header. Thus, the recipient's mail software must support Return-Receipt-To functionality. Some servers support both Return-Receipt-To and DSN, others - only one of them or even none. You can use both methods simultaneously.

The delivery confirmation does not yet guarantee the recipient has read the message. To get or set a string containing the e-mail address of the person which should receive the read confirmation message, use MailMessage.ConfirmRead property.

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)

Note: ConfirmRead functionality must be supported by the mail client used by the recipient (that software must support Disposition-Notification-To header).