【问题标题】:Collecting SMTP server using Mailkit with Mimekit使用 Mailkit 和 Mimekit 收集 SMTP 服务器
【发布时间】:2016-10-26 18:41:44
【问题描述】:

在尝试使用 MailKit 和 MimeKit 发送电子邮件时,有没有办法收集 SMTP 输出?

ps:我正在尝试将我的电子邮件代码从 Easymail 迁移到 Mimekit 和 Mailkit,如果这是一个相当基本的查询,我深表歉意。

【问题讨论】:

    标签: c# mailkit mimekit


    【解决方案1】:

    其实有一个FAQ关于这个,不过为了方便,我贴在这里:

    MailKit 的所有客户端实现都有一个构造函数,它采用漂亮的IProtocolLogger 接口来记录客户端/服务器通信。开箱即用,您可以使用方便的 ProtocolLogger 类。以下是一些如何使用它的示例:

    // log to a file called 'smtp.log'
    var client = new SmtpClient (new ProtocolLogger ("smtp.log"));
    
    // log to standard output (i.e. the console)
    var client = new SmtpClient (new ProtocolLogger (Console.OpenStandardOutput ()));
    

    【讨论】:

    • 谢谢!。我正在开发一个向 1000 人发送邮件的应用程序。我需要记录每次发送的结果。我只需要知道它是否已发送或是否因异常代码而失败。有没有一种简单的方法来同步收集 SMTP 服务器响应代码?我注意到方法 void Data (FormatOptions options, MimeMessage message, CancellationToken cancelToken, ITransferProgress progress) 确实有一个事件被触发 OnMessageSent (new MessageSentEventArgs (message, response.Response));。有没有办法让我在每次发送后收集它?。
    • 是的。它在每条消息发送后发出。
    • @jstedfast 使用新的 ProtocolLogger ("smtp.log") 每次运行程序时都会重写 LOG 文件,如何附加文件?这样之前的数据不会被删除?
    • 您可以实现自己的 IProtocolLogger 并使用它,但默认的 ProtocolLogger 类不支持。
    • @jstedfast 使用这种方法创建了一个快速而肮脏的implementation for log4Net
    猜你喜欢
    • 1970-01-01
    • 2019-12-31
    • 2020-09-17
    • 1970-01-01
    • 1970-01-01
    • 2017-11-02
    • 2015-07-23
    • 2019-09-03
    • 2020-05-18
    相关资源
    最近更新 更多