测试 SMTP 的替代方案?
我正在尝试开发一个发送电子邮件的应用程序,但我们的内部网络被锁定得非常严密,所以我无法使用我们的内部邮件服务器进行中继。
有人用过 no-ip.com 之类的东西吗?还有其他选择吗?
I'm trying to develop an app that sends email, and our internal network is locked down pretty tight, so I can't relay using our internal mail servers.
Has anyone ever used something like no-ip.com? Are there any other alternatives?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
如果您只需要检查电子邮件是否发送到正确的地址并包含正确的内容,最简单的方法是通过编辑应用程序或 web.config 文件来使用放置文件夹:
这将导致电子邮件邮件被创建为指定目录中的文件。您甚至可以加载文件并验证它们作为单元测试的一部分。
(正如 codekaizen 指出的,如果您不介意修改代码/硬编码放置文件夹并在调试/发布模式下具有不同的行为,也可以在代码中完成此操作。)
If you just need to check that the e-mails are being sent to the correct addresses and with the correct contents, the easiest way is to use a drop folder by editing the app or web.config file:
This will result in the e-mails being created as files in the specified directory. You can even then load the files and verify them as part of a unit test.
(As codekaizen points out, this can also be done in code if you don't mind modifying the code/hardcoding the drop folder and having the behavior differing in debug/release mode.)
我同意上述...设置您自己的测试 SMTP 服务器,并将其用于您的测试。
以下是一些可帮助您走上正轨的信息:
http://www.microsoft.com/technet/prodtechnol/WindowsServer2003/Library/IIS/e4cf06f5-9a36-474b-ba78-3f287a2b88f2.mspx?mfr=true
http://www.cmsconnect.com/praetor/WebHelpG2/Chapter_2_- _Pre-installation_considerations/Configuring_the_SMTP_Server.htm
http://service1 .symantec.com/support/ent-gate.nsf/docid/2007241920754398
I would agree with the above...setup your own test SMTP server, and use that for your testing.
Here's some info to get you on the right track:
http://www.microsoft.com/technet/prodtechnol/WindowsServer2003/Library/IIS/e4cf06f5-9a36-474b-ba78-3f287a2b88f2.mspx?mfr=true
http://www.cmsconnect.com/praetor/WebHelpG2/Chapter_2_-_Pre-installation_considerations/Configuring_the_SMTP_Server.htm
http://service1.symantec.com/support/ent-gate.nsf/docid/2007241920754398
您可以将电子邮件保存到磁盘:
You can save the email to disk:
来自 @codekaizen,使用 AutoFixture.xUnit [可作为同名的 XUnit 包]:-
CapturingSmtpClientFixture
仅在测试上下文中使用 -您所需要做的就是确保您的实际代码提供已连接的
SmtpClient
设置适合实时 SMTP 服务器的参数。(为了完整起见,这里是
TemporaryDirectoryFixture
):-和一个骨架
EmailSender
:Riffing from @codekaizen, using AutoFixture.xUnit [which is available as an XUnit package by that name]:-
CapturingSmtpClientFixture
is only used in a test context-All you need to do then is make sure your actual code supplies an
SmtpClient
that has been wired up with parameters appropriate to the live SMTP server.(For completeness, here is
TemporaryDirectoryFixture
):-and a skeleton
EmailSender
:通常的答案是在 IIS 下本地运行 SMTP,但您需要小心发送给谁。实际上,最好发送到您常用的 SMTP 服务器并仅定位您域内的帐户。
The usual answer is to run SMTP locally under IIS, but you need to be careful about who you're sending to. It might actually be better to send to your usual SMTP server and target only accounts within your domain.