Requesting Delivery Status Notifications (DSN)

In this article I am going to explain how to request Delivery Status Notifications (DSN) regarding email delivery.

Delivery notifications are used to trace, if the email is delivered, bounced or delayed.

You can find more information on how to process bounced messages here.

Please also note that there is a fundamental difference between Delivery Status Notifications (DSN, read receipts), which are sent by SMTP servers and
Message Delivery Notifications (MDN), which are sent by mail user agents (such as Outlook or AS2 interface).

In case of delayed or failed delivery email server will send an email containing DSN back to sender. Once mail is delivered to the recipient mailbox, delivery notification mail will be sent to the sender mailbox.

There are several delivery notification options, you can request when sending a massage:

  • DeliveryNotificationOptions.None – No notification information will be sent. The mail server will utilize its configured behavior to determine whether it should generate a delivery notification. Usually notification is send when failure or delay occurs.
  • DeliveryNotificationOptions.OnSuccess – Notify if the delivery is successful.
  • DeliveryNotificationOptions.OnFailure – Notify if the delivery is unsuccessful.
  • DeliveryNotificationOptions.Delay – Notify if the delivery is delayed.
  • DeliveryNotificationOptions.Never – A notification should not be generated under any circumstances.

You can set delivery notification options easily. Please check the below code. It is normal mail sending code with one additional line that requests delivery notification to be sent. It uses Smtp.Configuration.DeliveryNotification property:

using (Smtp smtp = new Smtp())
{
    smtp.Connect("smtp.example.com");
    smtp.UseBestLogin("user", "password");
    smtp.Configuration.DeliveryNotification = DeliveryNotificationOptions.OnFailure |
        DeliveryNotificationOptions.Delay;

    IMail email = Fluent.Mail.Text("Some text")
        .Subject("Some subject")
        .From(new MailBox("from@example.com"))
        .To(new MailBox("to@example.com"))
        .Create();

    smtp.SendMessage(email);

    smtp.Close();
}
Using smtp As New Smtp()
    smtp.Connect("smtp.example.com")
    smtp.UseBestLogin("user", "password")
    smtp.Configuration.DeliveryNotification =  _
        DeliveryNotificationOptions.OnFailure _
        Or DeliveryNotificationOptions.Delay

    Dim email As IMail = Fluent.Mail.Text("Some text") _
        .Subject("Some subject") _
        .From(New MailBox("from@example.com")) _
        .[To](New MailBox("to@example.com")) _
        .Create()

    smtp.SendMessage(email)

    smtp.Close()
End Using

Please note that SMTP servers may ignore requests for such notifications, especially OnSuccess options tend to be ignored.

Tags:    

Questions?

Consider using our Q&A forum for asking questions.