使用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
- 下一篇: Javascript设置cookie和获