springboot发送复杂邮件
@Resource
JavaMailSenderImpl javaMailSender;
public void sendEmail (String targetEmail,String content) {
MimeMessage mimeMessage=javaMailSender.createMimeMessage();
try {
MimeMessageHelper helper=new MimeMessageHelper(mimeMessage);
//邮件主题
helper.setSubject("下班提示小助手");
//邮件内容
helper.setText(content,true);
//发件人邮箱
helper.setFrom("自律<>");
//收件人邮箱
helper.setTo(targetEmail);
//发送
javaMailSender.send(mimeMessage);
System.out.println("成功");
}catch (Exception e){
e.getStackTrace();
System.out.println("失败");
}
}
}
发件内容
<html>
<head>
<meta charset="utf-8">
<title></title>
</head>
<style>
h1{
width: auto;
font-size:-webkit-xxx-large;
color: red;
text-align: center;
}
img{
margin-top: 20px;
}
</style>
<body>
<h1 >下班啦</h1>
<img src="https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fpic.bczp.cn%2Fuploadfiles%2Fhtml%2F20131205120236_0150.jpg&refer=http%3A%2F%2Fpic.bczp.cn&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=auto?sec=1661064121&t=f8e8cd17d40c3409b7c58ecb1f9118f1" >
<img src="https://gimg2.baidu.com/image_search/src=http%3A%2F%2Finews.gtimg.com%2Fnewsapp_bt%2F0%2F12957320047%2F641.jpg&refer=http%3A%2F%2Finews.gtimg.com&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=auto?sec=1661064055&t=ae8d6a2071ab45109f112908d53c7af0">
<img src="https://gimg2.baidu.com/image_search/src=http%3A%2F%2F5b0988e595225.cdn.sohucs.com%2Fimages%2F20190928%2F0115346a16a44a51bb62a6a07c29fab6.jpeg&refer=http%3A%2F%2F5b0988e595225.cdn.sohucs.com&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=auto?sec=1661063672&t=a77cf482ac2383498088f201da08cbdd"/>
<img src="https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fimg.adoutu.com%2Fpicture%2F1538231189795.gif&refer=http%3A%2F%2Fimg.adoutu.com&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=auto?sec=1661063973&t=a780e511ff19c60b7c6e8b47b741d907"/>
</body>
</html>