首页>代码>基于springboot2的发送邮件项目>/spring-boot-2.x_mail/src/main/java/cn/lijunkui/mail/MailServiceTest.java
package cn.lijunkui.mail;


import org.springframework.beans.factory.annotation.Autowired;

import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Service;


import java.util.ArrayList;
import java.util.List;


@Service
public class MailServiceTest {

//	public void main(String[] args){
//	   sendInlineResourceMail();
//
//	}
	
	@Autowired
	private MailService mailService;
	

	public void sendSimpleMail() {
		mailService.sendSimpleMail("76@qq.com", "这是一个测试邮件", "这是一个测试邮件");
	}
	

	public void sendHtmlMail() {
		String html= "<!DOCTYPE html>\r\n" + 
				"<html>\r\n" + 
				"<head>\r\n" + 
				"<meta charset=\"UTF-8\">\r\n" + 
				"<title>Insert title here</title>\r\n" + 
				"</head>\r\n" + 
				"<body>\r\n" + 
				"	<font color=\"red\">发送html</font>\r\n" + 
				"</body>\r\n" + 
				"</html>";
//		mailService.sendHtmlMail("8@qq.com", "这是一个测试邮件", html);
	}

	//3.添加定时任务
	@Scheduled(cron = "0/5 * * * * ?")
	public void sendInlineResourceMail() {
		String html= "<!DOCTYPE html>\r\n" +
				"<html>\r\n" +
				"<head>\r\n" +
				"<meta charset=\"UTF-8\">\r\n" +
				"<title>Insert title here</title>\r\n" +
				"</head>\r\n" +
				"<body>\r\n" +
				"<img src=\"cid:image1\"/> "+
				"<img src=\"cid:image2\"/> "+
				"	<font color=\"red\"><a>你好!</a></font>\r\n" +
				"</body>\r\n" +
				"</html>";
		List<InlineResource> list = new ArrayList<InlineResource>();
		String path = MailServiceTest.class.getClassLoader().getResource("jc.jpg").getPath();
		
		InlineResource resource = new InlineResource("image1",path);
		InlineResource resource2 = new InlineResource("image2",path);
		
		list.add(resource2);
		list.add(resource);
		mailService.sendInlineResourceMail("6@qq.com", "头像图片", html,list);
		//mailService.sendInlineResourceMail("******@163.com", "这是一个测试邮件", html,list);
	}
	

	public void sendAttachmentsMail() {
		String html= "<!DOCTYPE html>\r\n" + 
				"<html>\r\n" + 
				"<head>\r\n" + 
				"<meta charset=\"UTF-8\">\r\n" + 
				"<title>Insert title here</title>\r\n" + 
				"</head>\r\n" + 
				"<body>\r\n" + 
				"	<font color=\"red\">发送html</font>\r\n" + 
				"</body>\r\n" + 
				"</html>";
		String path = MailServiceTest.class.getClassLoader().getResource("image.jpg").getPath();
		mailService.sendAttachmentsMail("11658@qq.com", "这是一个测试邮件", html, path);
	}
	

	public void sendInlineResourceMailForGroupSending() {
		String html= "<!DOCTYPE html>\r\n" + 
				"<html>\r\n" + 
				"<head>\r\n" + 
				"<meta charset=\"UTF-8\">\r\n" + 
				"<title>Insert title here</title>\r\n" + 
				"</head>\r\n" + 
				"<body>\r\n" + 
				"<img src=\"cid:image1\"/> "+
				"<img src=\"cid:image2\"/> "+
				"	<font color=\"red\">发送html</font>\r\n" + 
				"</body>\r\n" + 
				"</html>";
		List<InlineResource> list = new ArrayList<InlineResource>();
		String path = MailServiceTest.class.getClassLoader().getResource("image.jpg").getPath();
		
		InlineResource resource = new InlineResource("image1",path);
		InlineResource resource2 = new InlineResource("image2",path);
		
		list.add(resource2);
		list.add(resource);
		String users[] = {"lwy@126.com","114938@qq.com"};
		mailService.sendInlineResourceMailForGroupSending(users, "头像图片", html,list);
		//mailService.sendInlineResourceMail("******@163.com", "这是一个测试邮件", html,list);
	}
	
}
最近下载更多
2363659936  LV2 2022年6月21日
King_wsk  LV18 2022年3月24日
bcli123  LV7 2021年12月30日
ideaCode  LV4 2021年9月24日
ericxu1116  LV24 2021年7月3日
chenxiufeng  LV4 2021年7月2日
pxqtsht  LV15 2021年6月18日
luesjim  LV11 2021年6月18日
国服后端  LV10 2021年5月21日
gshnlj  LV15 2020年9月22日
最近浏览更多
lzx602  LV3 4月15日
gao123456789  LV6 3月7日
Wky123456 2023年11月2日
暂无贡献等级
hbsoft2008  LV16 2023年10月19日
ZhangGb 2023年9月2日
暂无贡献等级
风间千月  LV13 2023年6月5日
annazhang  LV29 2023年4月7日
fantesy  LV17 2023年1月28日
不想起  LV9 2022年10月15日
wangjie49  LV7 2022年10月3日
顶部 客服 微信二维码 底部
>扫描二维码关注最代码为好友扫描二维码关注最代码为好友