MDN | Blog | Limilabs https://www.limilabs.com/blog Using Limilabs .net components Mon, 20 May 2019 16:20:45 +0000 en-US hourly 1 https://wordpress.org/?v=6.6.2 Creating read receipt (MDN) https://www.limilabs.com/blog/creating-read-receipt-mdn Wed, 27 Mar 2013 11:30:24 +0000 http://www.limilabs.com/blog/?p=3857 You can also read how to: Request a read receipt Create a read receipt Process a read receipt 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 […]

The post Creating read receipt (MDN) first appeared on Blog | Limilabs.

]]>

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

The post Creating read receipt (MDN) first appeared on Blog | Limilabs.

]]>
Processing a read receipt (MDN) https://www.limilabs.com/blog/processing-read-receipt-mdn Wed, 27 Mar 2013 11:00:33 +0000 http://www.limilabs.com/blog/?p=3876 You can also read how to: Request a read receipt Create a read receipt Process a read receipt In this article we’ll show how to process a 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 […]

The post Processing a read receipt (MDN) first appeared on Blog | Limilabs.

]]>
You can also read how to:

In this article we’ll show how to process a 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)

All MDNs for a received message are available through IMail.ReadReceipts property.

// C#

var eml = imap.GetMessageByUID(uid);
IMail email = new MailBuilder().CreateFromEml(eml);
MimeMessageDispositionNotification mdn = email.ReadReceipts[0];

string finalRecipient = mdn.FinalRecipient; 
      // recipient@example.com

DispositonActionMode actionmode = mdn.ActionMode; 
      // e.g. DispositonActionMode.ManualAction

DispositonSendingMode sendingMode = mdn.SendingMode; 
      // e.g. DispositonSendingMode.SentManually

string originalMessageID= mdn.OriginalMessageID; 
      // e.g. "message-id@original.com"

DispositonType dispositionType = mdn.Type; 
      // e.g. DispositonType.Displayed, DispositonType.Deleted
' VB.NET

Dim eml = imap.GetMessageByUID(uid)
Dim email As IMail = New MailBuilder().CreateFromEml(eml)
Dim mdn As MimeMessageDispositionNotification = email.ReadReceipts(0)

Dim finalRecipient As String = mdn.FinalRecipient 
     ' recipient@example.com

Dim actionmode As DispositonActionMode = mdn.ActionMode 
      ' e.g. DispositonActionMode.ManualAction

Dim sendingMode As DispositonSendingMode = mdn.SendingMode 
      ' e.g. DispositonSendingMode.SentManually

Dim originalMessageID As String = mdn.OriginalMessageID 
      ' e.g. "message-id@original.com"

Dim dispositionType As DispositonType = mdn.Type 
      ' e.g. DispositonType.Displayed, DispositonType.Deleted

The post Processing a read receipt (MDN) first appeared on Blog | Limilabs.

]]>
Requesting read receipt (MDN) https://www.limilabs.com/blog/requesting-read-receipt Sat, 25 Sep 2010 15:14:39 +0000 http://www.limilabs.com/blog/?p=1061 You can also read how to: Request a read receipt Create a read receipt Process a read receipt Message headers are commonly used to store various e-mail metadata such as spam filtering score, mail agent name or other flags. Several headers can be used to request a delivery receipt for the message. This will make […]

The post Requesting read receipt (MDN) first appeared on Blog | Limilabs.

]]>
You can also read how to:

Message headers are commonly used to store various e-mail metadata such as spam filtering score, mail agent name or other flags.

Several headers can be used to request a delivery receipt for the message. This will make the recipient’s mail client (such as Outlook) notify the sender if the user have read the message.

Please note that the reply is not mandatory – not all e-mail clients support it and those who do usually ask the user for a permission before sending the receipt. Even though, it is still a useful feature.

As usual different mail clients honor different headers: ‘Disposition-Notification-To’, ‘Return-Receipt-To’ and ‘X-Confirm-Reading-To’.

Mail.dll .NET email client provides you a single method for that: RequestReadReceipt() that copies all addresses from “From” collection or “Reply-To” collection to all those headers.

Read receipt requests may not always be honored. There are several reasons for that:

  • A mail client may not recognize the special Disposition-Notification-To header.
  • A mail client may not implement that functionality.
  • The end user may have that functionality turned off.
  • The end user may optionally not choose to send one for your particular email.

The following code sends email, that requests read receipt:

// C# version:

MailBuilder builder = new MailBuilder();
builder.From.Add(new MailBox("from@example.com", "Alice"));
builder.To.Add(new MailBox("to@example.com", "Bob"));
builder.Subject = "Please let me know if you like it";
builder.Html = "<html>....</html>";

builder.RequestReadReceipt();

IMail email = builder.Create();


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

' VB.NET version:

Dim builder As New MailBuilder()
builder.From.Add(New MailBox("from@example.com", "Alice"))
builder.[To].Add(New MailBox("to@example.com", "Bob"))
builder.Subject = "Please let me know if you like it"
builder.Html= "<html>....</html>"

builder.RequestReadReceipt()

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

    smtp.SendMessage(email)

    smtp.Close()
End Using

Fluent interface equivalents:

// C# version:

using Fluent = Limilabs.Mail.Fluent;

IMail email = Fluent.Mail.Html("<html>....</html>")
    .Subject("Please let me know if you like it")
    .From("from@example.com")
    .To("to@example.com")
    .RequestReadReceipt()
    .Create();

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

and as usual VB.NET code:

' VB.NET version:

Imports Fluent = Limilabs.Mail.Fluent;

Dim email As IMail = Fluent.Mail.Html("<html>....</html>") _
    .Subject("Please let me know if you like it") _
    .From("from@example.com") _
    .[To]("to@example.com") _
    .RequestReadReceipt() _
    .Create()

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

    smtp.SendMessage(email)

    smtp.Close()
End Using

The post Requesting read receipt (MDN) first appeared on Blog | Limilabs.

]]>