2017-07-11 41 views
0

私のアプリケーションから大量の電子メールを送信するために、@ jstedfast Mimekit/Mailkitライブラリを使用しています。各メールの配信ステータスを取得する方法を知りたいこれは私の最初の試行であり、いくつかのRnDの後には、レポートタイプ=配信ステータスを設定したり渡したりする必要があります。 。 また、DeliveryStatusNotificationをオーバーライドしてみましたが、何も見つかりませんでした。通知/ステータスを取得するには間違った方向に行っているかもしれません。mimekit/mailkitライブラリを使った電子メールの配信状況を取得します。

protected override DeliveryStatusNotification? GetDeliveryStatusNotifications(MimeMessage message, MailboxAddress mailbox) 
    {} 

@jstedfastがここでアクティブであることがわかりました。私はあなたの助けが必要です。私はこれを行うための指示を得ていませんでした。 ありがとうございます。

答えて

1

最初にやるべきことはドキュメントの例のようなサブクラス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で、report-typeの値はdelivery-statusです。言い換えれば

Content-Typeヘッダは次のようになります。

Content-Type: multipart/report; report-type=delivery-status; boundary=ajkfhkzfhkjhkjadskhz 

あなたはMimeMessage.Load()とのメッセージを解析するとBodyが期待ReportTypeプロパティ値を持つMultipartReportであれば、あなたは確認することができます。

そこから、タイプMessageDeliveryStatus(通常は2番目の部分です)の子パーツを見つけることができます。

そこからStatusGroupsプロパティ(http://www.mimekit.net/docs/html/P_MimeKit_MessageDeliveryStatus_StatusGroups.htmを参照)をチェックします。コレクション内の各HeaderListには、別の受信者に関する情報があります。

StatusGroupsドキュメントに記載されているRFCを読んで、必要なヘッダーと値を調べる必要があります。

+0

メールIDのようなバウンスメールを処理する方法はありますか?バウンスメールをチェックしたい –

+0

はい。その情報はヘッダーに表示されます。詳細はetcなどをお読みください。 – jstedfast

+0

私の答えをupvoteして受け入れることができますか?ありがとう! – jstedfast

関連する問題