Riaan
Riaan

Reputation: 33

C# Mailkit delivery status notification

I am creating an email management system using MailKit.

I need to track delivery but all I can find is the DeliveryStatusNotification enum, but nowhere to apply it.

What I have so far is:

var message = new MimeMessage();
DeliveryStatusNotification delivery = 
  DeliveryStatusNotification.Delay |
  DeliveryStatusNotification.Failure |
  DeliveryStatusNotification.Never |
  DeliveryStatusNotification.Success;
message.Headers.Add(new Header(HeaderId.ReturnReceiptTo, "[email protected]")); // Delivery report

Guide me in the right direction??

Upvotes: 3

Views: 4714

Answers (1)

jstedfast
jstedfast

Reputation: 38618

What you need to do is subclass SmtpClient and override the GetDeliveryStatusNotifications method:

class DSNSmtpClient : SmtpClient
{
    protected override DeliveryStatusNotification? GetDeliveryStatusNotifications (MimeMessage message, MailboxAddress mailbox)
    {
        if (/* some criteria for deciding whether to get DSN's... */)
            return DeliveryStatusNotification.Delay | 
                   DeliveryStatusNotification.Failure | 
                   DeliveryStatusNotification.Success;
        return null;
    }
}

Upvotes: 4

Related Questions