首页>代码>基于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     LV16
                2021年6月18日
            
            
        
                luesjim     LV11
                2021年6月18日
            
            
        
                国服后端     LV10
                2021年5月21日
            
            
        
                gshnlj     LV15
                2020年9月22日
            
            
        
 
                 
                 
                 最近浏览
最近浏览