Creating read receipt (MDN)

In this article we’ll show how to create and send read receipt.

Read receipts also known as MDNs or Message Delivery Notifications are used to notify the message sender that some action has happened with their message (it was displayed, processed, deleted)

Check if read receipt was requested

Although several email headers can be used by sender to request a read receipt (‘Disposition-Notification-To’, ‘Return-Receipt-To’, ‘X-Confirm-Reading-To’) checking if read receipt was requested is quite easy. You just need to use IMail.GetReadReceiptAddresses method.

This method checks all previously mentioned headers and removes duplicates. If the returned list is not empty, it means that sender have requested read receipt.

The recipient’s email software may silently ignore the request, or it may prompt the user for permission to send the MDN. There is no obligation or guarantee of the return-receipt sending.

// C#

IMail mail = ...

List<MailBox> addresses = mail.GetReadReceiptAddresses();
if (addresses.Count > 0)
{
    // Read receipt was requested
}
' VB.NET

Dim mail As IMail = ...

Dim addresses As List(Of MailBox) = mail.GetReadReceiptAddresses()
    ' Read receipt was requested
If addresses.Count > 0 Then
End If

Creating read receipt for a message

Use ReadReceiptBuilder class to create MailBuilder that can be used to create actual message (IMail).

// C#
IMail mail = ...

ReadReceiptBuilder mdnBuilder = new ReadReceiptBuilder(mail);
//mdnBuilder.ReadSubjectTemplate = "Read: [Original.Subject]";
//mdnBuilder.ReadTextTemplate = 
//  @"This is a confirmation that your message sent to [OriginalRecipient.Address] was displayed.";
MailBuilder builder = mdnBuilder.WasDisplayed(new MailBox("bob@example.com"));
IMail mdn = builder.Create();

' VB.NET

Dim mail As IMail = ...

Dim mdnBuilder As New ReadReceiptBuilder(mail)
'mdnBuilder.ReadSubjectTemplate = "Read: [Original.Subject]";
'mdnBuilder.ReadTextTemplate =  
'   @"This is a confirmation that your message sent to [OriginalRecipient.Address] was displayed.";
Dim builder As MailBuilder = mdnBuilder.WasDisplayed(New MailBox("bob@example.com"))
Dim mdn As IMail = builder.Create()

Creating new read receipt

You can use ReadReceiptBuilder constructor overloads to create new read receipt when you don’t have IMail object available. You’ll need original message-id however.

// C#

ReadReceiptBuilder mdnBuilder = new ReadReceiptBuilder("messageid@original.com", new MailBox("sender@original.com"));
MailBuilder builder = mdnBuilder.WasDisplayed(new MailBox("recipient@original.com"));
IMail mdn = builder.Create();
' VB.NET

Dim mdnBuilder As New ReadReceiptBuilder("messageid@original.com", New MailBox("sender@original.com"))
Dim builder As MailBuilder = mdnBuilder.WasDisplayed(New MailBox("recipient@original.com"))
Dim mdn As IMail = builder.Create()

Sending read receipt

There some restrictions regarding sending MDNs that you should consider, RFC 3798:

MDNs SHOULD NOT be sent automatically if the address in the
Disposition-Notification-To header differs from the address in the
Return-Path header (IMail.ReturnPath). In this case, confirmation
from the user SHOULD be obtained, if possible. If obtaining consent
is not possible (e.g., because the user is not online at the time),
then an MDN SHOULD NOT be sent.

Confirmation from the user SHOULD be obtained (or no MDN sent) if
there is no Return-Path header (IMail.ReturnPath) in the message, or if there is more
than one distinct address in the Disposition-Notification-To header (IMail.GetReadReceiptAddresses).

// C#

using(Smtp smtp = new Smtp())
{
    smtp.Connect("smtp.server.com");  // or ConnectSSL for SSL
    smtp.UseBestLogin("user", "password");
 
    smtp.SendMessage(mdn);                     
 
    smtp.Close();   
}  
' VB.NET

Using smtp As New Smtp()
    smtp.Connect("smtp.server.com")	' or ConnectSSL for SSL
    smtp.UseBestLogin("user", "password")

    smtp.SendMessage(mdn)

    smtp.Close()
End Using

Tags:     

Questions?

Consider using our Q&A forum for asking questions.