C#Mailkit交付状态通知

时间:2015-05-28 13:02:01

标签: c# notifications mailkit

我正在使用MailKit创建一个电子邮件管理系统。

我需要跟踪投放,但我能找到的只是DeliveryStatusNotification enum,但无处可用。

到目前为止我所拥有的是:

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

指导我正确的方向?

1 个答案:

答案 0 :(得分:2)

您需要做的是继承SmtpClient并覆盖GetDeliveryStatusNotifications方法:

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