使用spring mail发送html邮件
生活随笔
收集整理的这篇文章主要介绍了
使用spring mail发送html邮件
小编觉得挺不错的,现在分享给大家,帮大家做个参考.
为什么80%的码农都做不了架构师?>>>
序
本文展示一下如何使用spring mail来发送html邮件。
maven
<!-- email --><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-mail</artifactId></dependency>发送图片
public void send(String from, String[] toMails, String subject, String text,Map<String,Object> inlines) throws Exception{MimeMessage mimeMessage = mailSender.createMimeMessage();MimeMessageHelper helper = new MimeMessageHelper(mimeMessage, true);helper.setFrom(from);helper.setTo(toMails);helper.setSubject(subject);helper.setText(text, true); //支持html// 增加inlineif(inlines != null){for(Map.Entry<String,Object> entry: inlines.entrySet()){if(entry.getValue() instanceof ClassPathResource){helper.addInline(entry.getKey(), (Resource) entry.getValue());}}}mailSender.send(mimeMessage);}测试
- 发送实例
- 异常
错误码554
554 DT:SPM 发送的邮件内容包含了未被许可的信息,或被系统识别为垃圾邮件。请检查是否有用户发送病毒或者垃圾邮件;被网易邮箱识别为垃圾邮件了,有个歪招,就是把发送邮箱添加到cc里头
helper.setCc(from);doc
- springboot发送邮件的实现例子
- 企业退信的常见问题?
转载于:https://my.oschina.net/go4it/blog/1536169
总结
以上是生活随笔为你收集整理的使用spring mail发送html邮件的全部内容,希望文章能够帮你解决所遇到的问题。
- 上一篇: Linus Torvalds将中国亮相L
- 下一篇: 使用 docker 搭建 web 服务环