使用 Java 邮件服务器进行测试
我正在测试一个应用程序,该应用程序从邮箱中取出邮件,根据该邮件的内容执行某些操作,然后根据操作的结果发送响应邮件。
我正在寻找一种为此应用程序编写测试的方法。理想情况下,我希望这些测试能够启动自己的邮件服务器,将我的测试电子邮件推送到该邮件服务器上的文件夹,并让我的应用程序从我的测试启动的邮件服务器中抓取邮件。
配置应用程序以使用邮件服务器并不困难,但我不知道在哪里可以找到用 Java 启动邮件服务器的编程方法。我看过 JAMES,但我无法弄清楚如何从我的测试中启动服务器。
所以问题是这样的:我可以使用什么来构建可以完全在 Java 中配置和启动的 Java 邮件服务器?
I'm in the process of testing an application that takes mail out of a mailbox, performs some action based on the content of that mail, and then sends a response mail depending on the result of the action.
I'm looking for a way to write tests for this application. Ideally, I'd like for these tests to bring up their own mail server, push my test emails to a folder on this mail server, and have my application scrape the mail out of the mail server that my test started.
Configuring the application to use the mailserver is not difficult, but I do not know where to look for a programatic way of starting a mail server in Java. I've looked at JAMES, but I am unable to figure out how to start the server from within my test.
So the question is this: What can I use for a mail server in Java that I can configure and start entirely within Java?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
使用起来也非常简单GreenMail,它被设计为用于自动“单元”测试的邮件服务器。
从项目网页(现在可能还有一些其他具有发送/接收功能的工具):
There is also very simple in use GreenMail which was designer as a mail server for automatic "unit" tests.
From projects web page (probably there are some others tools with sending/receiving functionality nowadays):
我使用过 Dumbster 和 SubEthaSmtp 在单元测试之前测试发送电子邮件的代码。
我发现与 Dumbster 合作要容易得多。
I've used both Dumbster and SubEthaSmtp in unit tests before to test code that sends email.
I found Dumbster to be far easier to work with.
看看JES,似乎做你想做的。
Take a look at JES, seems to do what you want.
Dumster:设置速度很快!但无法处理邮件附件。正文末尾只有字符串,必须单独解析。
所以现在我正在尝试另一个框架
Dumbster: Fast to setup! But can't handle mail attachments. There only strings at the end of the body and have to be parsed separately.
So now I'm trying another framework
Mock-JavaMail 项目
是我在为 Jenkins 开发插件时遇到的,它是一个梦想使用!
只需 删除依赖项进入您的项目,您就可以开始了(我将让 Kohsuke 解释如何设置和使用它)。
如果您不耐烦,这里有一个如何使用它的快速示例:
示例:
The Mock-JavaMail project
I came across it when developing a plugin for Jenkins, and it's been a dream to use!
Just drop the dependency into your project, and you're ready to go (I'll let Kohsuke explain how to set it up and use it).
If you're impatient, here's a quick example of how it's used:
Example: