简体   繁体   English

向本地主机发送电子邮件/“捕获”外发电子邮件

[英]Sending E-mail to localhost / "capturing" outgoing e-mail

I work with a dozen pieces of equipment whose operating software has the option to send e-mails on error.我使用了十几台设备,它们的操作软件可以选择在出错时发送电子邮件。 I would prefer to capture the details of that e-mail on the host PCs that run them (ie for logging, communicating details automatically via Slack, etc.) rather than them going to an inbox somewhere.我更愿意在运行它们的主机 PC 上捕获该电子邮件的详细信息(即用于日志记录、通过 Slack 自动传达详细信息等),而不是将它们发送到某个地方的收件箱。

Is there a way to have the software e-mail an address that is essentially a lightweight piece of code running on the same PC mimicking something like an SMTP server (that will allow me to get after the message's contents)?有没有办法让软件通过电子邮件发送一个地址,该地址本质上是一个在同一台 PC 上运行的轻量级代码,模仿 SMTP 服务器之类的东西(这将允许我获取邮件的内容)? Other solutions I have seen are along the lines of setting up a full-blown server which seems like overkill.我见过的其他解决方案是建立一个完整的服务器,这似乎有点矫枉过正。

You may configure SmtpClient to save email to a specific folder instead of sending it over the wire.您可以将SmtpClient配置为将电子邮件保存到特定文件夹,而不是通过网络发送。 Check this answer.检查这个答案。

Also you must design your system in the way it could work with different implementations of your 'sender', so that you can replace it when you need that, for example during testing.此外,您必须设计您的系统,使其能够与您的“发送者”的不同实现一起工作,以便您可以在需要时更换它,例如在测试期间。 In this case you can easily provide proxy implementation that will capture email content and then send it to localhost , or add aspects (make retries, logs performance...).在这种情况下,您可以轻松提供代理实现来捕获电子邮件内容,然后将其发送到localhost ,或添加方面(进行重试、记录性能...)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM