简体   繁体   中英

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, "test@example.com")); // Delivery report

Guide me in the right direction??

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;
    }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM