使用 Mailkit 和 Mimekit 收集 SMTP 服务器

Collecting SMTP server using Mailkit with Mimekit

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

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

实际上有一个 FAQ 关于这个,但为了方便,我将其粘贴在这里:

MailKit 的所有客户端实现都有一个构造函数,它采用漂亮的 IProtocolLogger interface for logging client/server communications. Out of the box, you can use the handy ProtocolLogger class。以下是如何使用它的一些示例:

// 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 ()));