【发布时间】:2016-10-26 18:41:44
【问题描述】:
在尝试使用 MailKit 和 MimeKit 发送电子邮件时,有没有办法收集 SMTP 输出?
ps:我正在尝试将我的电子邮件代码从 Easymail 迁移到 Mimekit 和 Mailkit,如果这是一个相当基本的查询,我深表歉意。
【问题讨论】:
在尝试使用 MailKit 和 MimeKit 发送电子邮件时,有没有办法收集 SMTP 输出?
ps:我正在尝试将我的电子邮件代码从 Easymail 迁移到 Mimekit 和 Mailkit,如果这是一个相当基本的查询,我深表歉意。
【问题讨论】:
其实有一个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 ()));
【讨论】: