`
rensanning
  • 浏览: 3513876 次
  • 性别: Icon_minigender_1
  • 来自: 大连
博客专栏
Efef1dba-f7dd-3931-8a61-8e1c76c3e39f
使用Titanium Mo...
浏览量:37478
Bbab2146-6e1d-3c50-acd6-c8bae29e307d
Cordova 3.x入门...
浏览量:604304
C08766e7-8a33-3f9b-9155-654af05c3484
常用Java开源Libra...
浏览量:678049
77063fb3-0ee7-3bfa-9c72-2a0234ebf83e
搭建 CentOS 6 服...
浏览量:87250
E40e5e76-1f3b-398e-b6a6-dc9cfbb38156
Spring Boot 入...
浏览量:399811
Abe39461-b089-344f-99fa-cdfbddea0e18
基于Spring Secu...
浏览量:69066
66a41a70-fdf0-3dc9-aa31-19b7e8b24672
MQTT入门
浏览量:90468
社区版块
存档分类
最新评论

Java单元测试之邮件测试-GreenMail

    博客分类:
  • Java
 
阅读更多
比较流行的Java的SMTP开源组件有:


其中 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();
}
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics