您需要做的第一件事是子类 SmtpClient,如文档中的示例:
http://www.mimekit.net/docs/html/M_MailKit_Net_Smtp_SmtpClient_GetDeliveryStatusNotifications.htm
public class DSNSmtpClient : SmtpClient
{
public DSNSmtpClient ()
{
}
/// <summary>
/// Get the envelope identifier to be used with delivery status notifications.
/// </summary>
/// <remarks>
/// <para>The envelope identifier, if non-empty, is useful in determining which message
/// a delivery status notification was issued for.</para>
/// <para>The envelope identifier should be unique and may be up to 100 characters in
/// length, but must consist only of printable ASCII characters and no white space.</para>
/// <para>For more information, see rfc3461, section 4.4.</para>
/// </remarks>
/// <returns>The envelope identifier.</returns>
/// <param name="message">The message.</param>
protected override string GetEnvelopeId (MimeMessage message)
{
// Since you will want to be able to map whatever identifier you return here to the
// message, the obvious identifier to use is probably the Message-Id value.
return message.MessageId;
}
/// <summary>
/// Get the types of delivery status notification desired for the specified recipient mailbox.
/// </summary>
/// <remarks>
/// Gets the types of delivery status notification desired for the specified recipient mailbox.
/// </remarks>
/// <returns>The desired delivery status notification type.</returns>
/// <param name="message">The message being sent.</param>
/// <param name="mailbox">The mailbox.</param>
protected override DeliveryStatusNotification? GetDeliveryStatusNotifications (MimeMessage message, MailboxAddress mailbox)
{
// In this example, we only want to be notified of failures to deliver to a mailbox.
// If you also want to be notified of delays or successful deliveries, simply bitwise-or
// whatever combination of flags you want to be notified about.
return DeliveryStatusNotification.Failure;
}
}
这将告诉 SMTP 服务器向您发送有关您发送的每封邮件的传递状态的电子邮件。
这些消息将具有顶级 MIME 类型multipart/report
with a report-type
的价值delivery-status
.
换句话说,Content-Type
标题将如下所示:
Content-Type: multipart/report; report-type=delivery-status; boundary=ajkfhkzfhkjhkjadskhz
一旦你解析消息MimeMessage.Load()
,您可以检查是否Body
is a MultipartReport
与预期的ReportType
适当的价值。
从那里,您可以找到类型为的子部件MessageDeliveryStatus
(我认为通常是第二部分)。
从那里,您将需要检查StatusGroups
财产(见http://www.mimekit.net/docs/html/P_MimeKit_MessageDeliveryStatus_StatusGroups.htm) - 每个HeaderList
集合中将包含不同收件人的信息。
您需要阅读 StatusGroups 文档中列出的 RFC,以找出您需要查找的可能标头和值。