/**
* Project: AccountEmail
* <p>
* File Created at 2018/5/27
* <p>
* Copyright 2018 e-dewin.com Corporation Limited.
* All rights reserved.
* <p>
* This software is the confidential and proprietary information of
* dewin Company. ("Confidential Information"). You shall not
* disclose such Confidential Information and shall use it only in
* accordance with the terms of the license agreement you entered into
* with e-dewin.com.
*/
package com.juvenxu.mvnbook.account.email;
import com.icegreen.greenmail.util.GreenMail;
import com.icegreen.greenmail.util.GreenMailUtil;
import com.icegreen.greenmail.util.ServerSetup;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import javax.mail.internet.MimeMessage;
import static junit.framework.Assert.assertEquals;
/**
* @Description:
* @author: hxw
* @version 1.0
* @date: 2018/5/27 14:16
*/
public class AccountEmailServiceTest {
private GreenMail greenMail;
@Before //先于测试方法执行
public void startMailServer() throws Exception{
greenMail = new GreenMail(ServerSetup.SMTP);
//创建邮件账户并启动邮件服务
greenMail.setUser("test@juvenxu.com","123456");
greenMail.start();
}
@Test
public void testSendMail()throws Exception{
ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext("account-email.xml");
AccountEmailService accountEmailService = (AccountEmailService)ctx.getBean("accountEmailService");
String subject = "Test Subject";
String htmlText = "<h3>Test</h3>";
accountEmailService.sendMail("test2@juvenxu.com",subject,htmlText);
greenMail.waitForIncomingEmail(2000,1);
MimeMessage[] msgs = greenMail.getReceivedMessages();
assertEquals(1,msgs.length);
assertEquals(subject,msgs[0].getSubject());
assertEquals(htmlText, GreenMailUtil.getBody(msgs[0]).trim());
}
@After
public void stopMailServer() throws Exception{
greenMail.stop();
}
}
![avatar](https://profile-avatar.csdnimg.cn/bc3c40a1700d40bc91a04af0dc7133fa_weixin_41883161.jpg!1)
九转成圣
- 粉丝: 3644
- 资源: 2956
最新资源
- Carsim Simulink联合仿真基于LQR 模糊PID 滑模控制的横摆稳定性控制系统 综合跟随理想横摆角速度的方法和抑制汽
- 江科大STM32学习笔记(上)
- 基于MFC实现ModbusRTU转ModbusTCP的源码
- 串联式、并联式、混联式混合动力系统simulink控制策略模型(串联式、并联式、混联式每个都是独立的需要单独说拿哪个,默认是混联
- NiceCat.zip
- svn客户端安装包 windows 环境
- 蒙特卡洛模拟两相流气泡pdp-sim-tbf-master.zip
- 30a4882db91186b8.png
- 蒙特卡洛五子棋typescript实现mcts-ts-main.zip
- 使用WinRAR打开RAR文件.pdf
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
![feedback](https://img-home.csdnimg.cn/images/20220527035711.png)
![feedback](https://img-home.csdnimg.cn/images/20220527035711.png)
![feedback-tip](https://img-home.csdnimg.cn/images/20220527035111.png)