3

我正在使用 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

指引我正确的方向??

4

1 回答 1

4

您需要做的是继承 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;
    }
}
于 2015-05-29T11:13:34.990 回答