在 .NET 中使用 SmtpClient 时如何捕获 SMTP 转录本
我想知道在使用 System.Net.Mail.MailClient 发送电子邮件时是否有一种简单的方法来捕获 SMTP 会话的记录。如果生成错误(例如:中继被拒绝),我想向用户显示整个记录。
如果之前有讨论过这个问题,我无法找到它们。我正在使用 VB.NET,但 C# 示例也很受欢迎。预先感谢您的任何建议!
干杯, 乙脑
I would like to know if there is a simple way to capture a transcript of the SMTP session when sending email using the System.Net.Mail.MailClient. In cases where an error is generated (ex: relaying denied) I would like to display the whole transcript to the user.
If there are previous questions that discuss this I was unable to find them. I am working with VB.NET, but C# examples are also appreciated. Thanks in advance for any suggestions!
Cheers,
JE
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为您可以通过 打开系统日志记录来获取实际的成绩单.net。不幸的是,我认为这不是实时的,所以它不适合您。相反,您只需尝试发送和捕获 SmtpException,然后检查 SmtpException .StatusCode。
如果您有另一个进程为您发送(例如 IIS),并且您基本上只是发送消息以供其传递,那么不幸的是,没有真正的方法可以实时获取其中一些异常。
这里有一篇有趣的 SMTP 测试器帖子,我从未尝试过,但听起来很有趣。
我可以在调用 client.Send() 之前测试 SmtpClient 吗?
I think you can get the actual transcript by turning on logging for system.net. Unfortunately I don't think this is real-time so its not an option for you. Instead you'll just have to try sending and catching the SmtpException and then inspecting the SmtpException.StatusCode.
If you're having another process send for you (such as IIS) and you're basically just dropping off messages for it to deliver then there's no real way to get some of these exceptions in real-time unfortunately.
There is an interesting SMTP-tester post here that I've never tried but sounds interesting.
Can I test SmtpClient before calling client.Send()?