最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

使用spring mail發(fā)送html郵件的示例代碼

 更新時間:2017年09月13日 11:06:39   作者:xixicat  
本篇文章主要介紹了使用spring mail發(fā)送html郵件的示例代碼,這里整理了詳細(xì)的示例代碼,具有一定的參考價值,有興趣的可以了解一下


本文展示一下如何使用spring mail來發(fā)送html郵件。

maven

    <!-- email -->
    <dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter-mail</artifactId>
    </dependency>

發(fā)送圖片

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

    // 增加inline
    if(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);
  }

測試

發(fā)送實(shí)例

    ClassPathResource classPathResource = new ClassPathResource("image_2.png");
    Map<String,Object> att = new HashMap<>();
    att.put("image",classPathResource);
    String content = "<html>
              <body>
                <h4>spring mail發(fā)送實(shí)例</h4>
                <img src='cid:image'/><br>
              </body>
             </html>";
    try{
      mailService.send(new String[]{"xxxxx@163.com"},"spring mail發(fā)送實(shí)例",content,att);
    }catch (Exception e){
      e.printStackTrace();
    }

異常

org.springframework.mail.MailSendException: Failed messages: com.sun.mail.smtp.SMTPSendFailedException: 554 DT:SPM 126 smtp7,DsmowAB3U6X1_LdZjIz+Aw--.26008S3 1505230070,please see http://mail.163.com/help/help_spam_16.htm?ip=123.65.107.103&hostid=smtp7&time=1505230070
; message exception details (1) are:
Failed message 1:
com.sun.mail.smtp.SMTPSendFailedException: 554 DT:SPM 126 smtp7,DsmowAB3U6X1_LdZjIz+Aw--.26008S3 1505230070,please see http://mail.163.com/help/help_spam_16.htm?ip=123.65.107.103&hostid=smtp7&time=1505230070

  at com.sun.mail.smtp.SMTPTransport.issueSendCommand(SMTPTransport.java:2267)
  at com.sun.mail.smtp.SMTPTransport.finishData(SMTPTransport.java:2045)
  at com.sun.mail.smtp.SMTPTransport.sendMessage(SMTPTransport.java:1260)
  at org.springframework.mail.javamail.JavaMailSenderImpl.doSend(JavaMailSenderImpl.java:448)
  at org.springframework.mail.javamail.JavaMailSenderImpl.send(JavaMailSenderImpl.java:345)
  at org.springframework.mail.javamail.JavaMailSenderImpl.send(JavaMailSenderImpl.java:340)

錯誤碼554

554 DT:SPM 發(fā)送的郵件內(nèi)容包含了未被許可的信息,或被系統(tǒng)識別為垃圾郵件。請檢查是否有用戶發(fā)送病毒或者垃圾郵件;

被網(wǎng)易郵箱識別為垃圾郵件了,有個歪招,就是把發(fā)送郵箱添加到cc里頭

helper.setCc(from);

以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

最新評論

侯马市| 隆安县| 承德市| 安西县| 伊吾县| 沈丘县| 江华| 青岛市| 江口县| 榕江县| 沈阳市| 井陉县| 武宁县| 宿州市| 辉南县| 冀州市| 汉中市| 探索| 香格里拉县| 静安区| 辽宁省| 榕江县| 禹州市| 咸宁市| 平江县| 雷州市| 崇义县| 哈尔滨市| 新巴尔虎右旗| 米林县| 梅河口市| 姚安县| 兴和县| 惠州市| 景谷| 离岛区| 南部县| 贡觉县| 论坛| 上虞市| 鱼台县|