比较流行的Java的SMTP开源组件有:
其中 GreenMail 是最适合做单元测试的,它本身并不会发送邮件,但支持SMTP, POP3, IMAP。发布的时间也很长了,不过知道的人并不多。如果做发送邮件代码的单元测试,不想走邮件服务器,也不想mock的话,GreenMail 是个很好的选择。
http://www.icegreen.com/greenmail/
目前版本:greenmail-1.3.1b.jar
Roadmap显示在1.4+版本中将会用 SubEthaSMTP 代替目前GreenMail自身的SMTP代码。
- Apache James Server http://james.apache.org/
- JES(Java Email Server) http://www.ericdaugherty.com/java/mailserver/
- SubEthaSMTP http://code.google.com/p/subethasmtp/
- Dumbster http://quintanasoft.com/dumbster/
- GreenMail http://www.icegreen.com/greenmail/
其中 GreenMail 是最适合做单元测试的,它本身并不会发送邮件,但支持SMTP, POP3, IMAP。发布的时间也很长了,不过知道的人并不多。如果做发送邮件代码的单元测试,不想走邮件服务器,也不想mock的话,GreenMail 是个很好的选择。
引用
GreenMail is an embeddable, lightweight and sandboxed email server for testing and developing purposes
http://www.icegreen.com/greenmail/
目前版本:greenmail-1.3.1b.jar
Roadmap显示在1.4+版本中将会用 SubEthaSMTP 代替目前GreenMail自身的SMTP代码。
- private static void testSMTPCode() throws Exception {
- GreenMail greenMail = new GreenMail();
- greenMail.start();
- // Sending
- GreenMailUtil.sendTextEmailTest("to@localhost.com", "from@localhost.com", "subject", "body");
- // Retrieving
- String msg = GreenMailUtil.getBody(greenMail.getReceivedMessages()[0]);
- System.out.println(msg);
- greenMail.stop();
- }
- private static void testSMTPSCode() throws Exception {
- GreenMail greenMail = new GreenMail();
- greenMail.start();
- // Sending
- GreenMailUtil.sendTextEmailSecureTest("to@localhost.com", "from@localhost.com", "subject", "body");
- // Retrieving
- String msg = GreenMailUtil.getBody(greenMail.getReceivedMessages()[0]);
- System.out.println(msg);
- greenMail.stop();
- }
- private static void testSpecialPort() throws Exception {
- ServerSetup ss = new ServerSetup(3025, null, "smtp");
- GreenMail greenMail = new GreenMail(ss);
- greenMail.start();
- GreenMailUtil.sendTextEmail("to@localhost.com", "from@localhost.com", "subject", "body", ss);
- greenMail.stop();
- }