ServiceTest.java
2.15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
package com.huaheng.test;
import com.huaheng.pc.config.sendMail.service.MailService;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;
import javax.annotation.Resource;
/**
* Created by Enzo Cotter on 2019/9/6.
*/
@RunWith(SpringRunner.class)
@SpringBootTest
public class ServiceTest {
@Resource
private MailService mailService;
/**
* 发送简单纯文本邮件
*/
@Test
public void sendSimpleMail() {
String[] to = {"752432958@qq.com"};
String[] cc = {};
mailService.sendSimpleMail(to, "发送邮件测试", "大家好,这是我用springboot进行发送邮件测试",cc);
}
/**
* 发送HTML邮件
*/
@Test
public void sendHtmlMail() {
String[] to = {"752432958@qq.com"};
String[] cc = {};
String content = "<html><body><h3><font color=\"red\">" + "大家好,这是springboot发送的HTML邮件" + "</font></h3></body></html>";
mailService.sendHtmlMail(to, "发送邮件测试", content, cc);
}
/**
* 发送带附件的邮件
*/
@Test
public void sendAttachmentMail() {
String[] to = {"752432958@qq.com"};
String[] cc = {};
String content = "<html><body><h3><font color=\"red\">" + "大家好,这是springboot发送的HTML邮件,有附件哦" + "</font></h3></body></html>";
String filePath = "your file path";
mailService.sendAttachmentMail(to, "发送邮件测试", content, filePath, cc);
}
/**
* 发送带图片的邮件
*/
@Test
public void sendInlineResourceMail() {
String[] to = {"752432958@qq.com"};
String[] cc = {};
String rscPath = "your picture path";
String rscId = "skill001";
String content = "<html><body><h3><font color=\"red\">" + "大家好,这是springboot发送的HTML邮件,有图片哦" + "</font></h3>"
+ "<img src=\'cid:" + rscId + "\'></body></html>";
mailService.sendInlineResourceMail(to, "发送邮件测试", content, rscPath, rscId, cc);
}
}