/**
* 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();
}
}
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
读书笔记:maven实战学习.zip (36个子文件)
读书笔记:maven实战学习
MavenLearn
pom.xml 2KB
src
test
resources
service.properties 176B
java
com
juvenxu
mvnbook
account
email
AccountEmailServiceTest.java 2KB
main
resources
account-email.xml 1KB
java
com
juvenxu
mvnbook
account
email
AccountEmailService.java 337B
AccountEmailException.java 909B
AccountEmailServiceImpl.java 2KB
.git
index 3KB
HEAD 23B
refs
heads
master 41B
tags
remotes
origin
master 41B
objects
pack
pack-bc02111669a49a09e34176d5f4d0bc49cb1de594.idx 3KB
pack-bc02111669a49a09e34176d5f4d0bc49cb1de594.pack 13KB
info
FETCH_HEAD 121B
logs
HEAD 130B
refs
heads
master 130B
remotes
origin
master 144B
hooks
config 258B
branches
.idea
.name 12B
uiDesigner.xml 9KB
libraries
Maven__aopalliance_aopalliance_1_0.xml 502B
Maven__org_springframework_spring_core_2_5_6.xml 548B
Maven__com_icegreen_greenmail_1_3_1b.xml 513B
Maven__org_springframework_spring_beans_2_5_6.xml 555B
Maven__javax_activation_activation_1_1.xml 515B
Maven__org_springframework_spring_context_support_2_5_6.xml 625B
Maven__junit_junit_4_7.xml 436B
Maven__org_slf4j_slf4j_api_1_3_1.xml 494B
Maven__org_springframework_spring_context_2_5_6.xml 569B
Maven__javax_mail_mail_1_4_1.xml 463B
Maven__commons_logging_commons_logging_1_1_1.xml 560B
workspace.xml 26KB
misc.xml 439B
compiler.xml 622B
modules.xml 250B
maven.iml 2KB
共 36 条
- 1
资源评论
九转成圣
- 粉丝: 5168
- 资源: 2961
下载权益
C知道特权
VIP文章
课程特权
开通VIP
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功