前言:前一天调用163邮箱发送邮件还么有问题,今天再调用就各种发送不成功,害的我都关闭授权,还花了一毛钱短信费重新开启授权,最后百度到了一篇文章,非常贴切,在此转载下。

本人遇到的错误代码是554,邮件主题和内容有敏感词汇(您的验证码是),或者被当作垃圾邮件,修改了一下主题和内容就OK了。

使用springboot向163邮箱发送邮件遇到一些问题,主要归为如下几点:

1.连接smtp.163.com异常,报错:java.net.UnknownHostException: smtp.163.com
2.用户权限不足,报错:javax.mail.AuthenticationFailedException: 550 User has no permission
3.认证错误,报错:javax.mail.AuthenticationFailedException: 535 Error: authentication failed
4.发送内容错误,报错:com.sun.mail.smtp.SMTPSendFailedException: 554 DT:SPM
5.发送附件错误,报错:javax.mail.MessagingException: Empty multipart: multipart/related; 
6.发送静态图片资源,查看邮件,图片显示不出来

问题1:

详细报错如下:

org.springframework.mail.MailSendException: Mail server connection failed; nested exception is 

com.sun.mail.util.MailConnectException: Couldn't connect to host, port: smtp.163.com , 25; timeout
-1;
nested exception is:
java.net.UnknownHostException: smtp.163.com . Failed messages:
com.sun.mail.util.MailConnectException: Couldn't connect to host, port: smtp.163.com , 25; timeout -1;
nested exception is:
java.net.UnknownHostException: smtp.163.com ; message exception details (1) are:
Failed message 1:
com.sun.mail.util.MailConnectException: Couldn't connect to host, port: smtp.163.com , 25; timeout -1;
nested exception is:
java.net.UnknownHostException: smtp.163.com
at com.sun.mail.smtp.SMTPTransport.openServer(SMTPTransport.java:2118)
at com.sun.mail.smtp.SMTPTransport.protocolConnect(SMTPTransport.java:712)
at javax.mail.Service.connect(Service.java:366)
at org.springframework.mail.javamail.JavaMailSenderImpl.connectTransport (JavaMailSenderImpl.java:501)
at org.springframework.mail.javamail.JavaMailSenderImpl.doSend(JavaMailSenderImpl.java:421)
at org.springframework.mail.javamail.JavaMailSenderImpl.send(JavaMailSenderImpl.java:345)
at org.springframework.mail.javamail.JavaMailSenderImpl.send(JavaMailSenderImpl.java:340)
at mail.service.MailSendService.sendInlineMail(MailSendService.java:111)

解决思路:
1.进行telnet检查,查看telent smtp.163.com 25,发现可以正常telent成功,说明网络没问题
2.查看配置是否正常,经查看,发现springboot的application.properties文件中spring.mail.host=smtp.163.com后面有空格,去掉空格即可

问题2:

详细报错如下:

org.springframework.mail.MailAuthenticationException: Authentication failed; nested exception is

javax.mail.AuthenticationFailedException: 550 User has no permission

  at org.springframework.mail.javamail.JavaMailSenderImpl.doSend(JavaMailSenderImpl.java:424)
  at org.springframework.mail.javamail.JavaMailSenderImpl.send(JavaMailSenderImpl.java:345)
  at org.springframework.mail.javamail.JavaMailSenderImpl.send(JavaMailSenderImpl.java:340)
  at mail.service.MailSendService.sendInlineMail(MailSendService.java:111)
  at mail.test.TestMail.test(TestMail.java:43)
  at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
  at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
  at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
  at java.lang.reflect.Method.invoke(Unknown Source)
  at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
  at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
  at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
  at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)

解决思路:
1.在cn.bing.com上搜索,发现有该问题的先例,问题原因是没有开启163邮箱的pop3/smtp协议
  参考文档:http://www.cnblogs.com/cosyer/p/6676023.html
2.登录163邮箱->设置->POP3/SMTP/IMAP设置->开启协议,正确设置授权码

问题3:

详细报错如下:

javax.mail.AuthenticationFailedException: 535 Error: authentication failed

    at org.springframework.mail.javamail.JavaMailSenderImpl.doSend(JavaMailSenderImpl.java:424)
at org.springframework.mail.javamail.JavaMailSenderImpl.send(JavaMailSenderImpl.java:345)
at org.springframework.mail.javamail.JavaMailSenderImpl.send(JavaMailSenderImpl.java:340)
at mail.service.MailSendService.sendInlineMail(MailSendService.java:111)
at mail.test.TestMail.test(TestMail.java:43)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)

解决思路:
1.163邮箱开通smtp服务后,javaMail发送邮箱要使用授权码作为登录密码
2.设置spring.mail.password=授权码

问题4:

详细报错如下:

org.springframework.mail.MailSendException: Failed messages: 

com.sun.mail.smtp.SMTPSendFailedException: 554 DT:SPM 163 smtp11,D8CowACX7CmSHB5b3SrlCA--.26635S3 

1528700051,please see http://mail.163.com/help/help_spam_16.htm?

ip=182.138.102.204&hostid=smtp11&time=1528700051
at org.springframework.mail.javamail.JavaMailSenderImpl.doSend(JavaMailSenderImpl.java:474) ~[spring-context-support-4.3.13.RELEASE.jar:4.3.13.RELEASE]
at org.springframework.mail.javamail.JavaMailSenderImpl.send(JavaMailSenderImpl.java:307) ~[spring-context-support-4.3.13.RELEASE.jar:4.3.13.RELEASE]
at org.springframework.mail.javamail.JavaMailSenderImpl.send(JavaMailSenderImpl.java:296) ~[spring-context-support-4.3.13.RELEASE.jar:4.3.13.RELEASE]
at mail.service.MailSendService.sendSimpleMail(MailSendService.java:50) ~[classes/:na]
at mail.test.TestMail.test(TestMail.java:36) [classes/:na]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.7.0_80]
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[na:1.7.0_80]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[na:1.7.0_80]
at java.lang.reflect.Method.invoke(Unknown Source) ~[na:1.7.0_80]
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50) [junit-4.12.jar:4.12]
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12) [junit-4.12.jar:4.12]
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47) [junit-4.12.jar:4.12]
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)

解决思路:
1.根据错误提示,查看如下url:
http://mail.163.com/help/help_spam_16.htmip=182.138.102.204&hostid=smtp11&time=1528700051
 这是163邮箱提供的一个错误码对应表
2.554 DT:SPM对应错误为:
 发送的邮件内容包含了未被许可的信息,或被系统识别为垃圾邮件。请检查是否有用户发送病毒或者垃圾邮件
3.修改邮件的主题及内容,使用合法信息,例如不要使用:test、测试这些信息

问题5:

详细报错如下:

Caused by: javax.mail.MessagingException: Empty multipart: multipart/related;
boundary="----=_Part_2_1115361411.1528698722005"
at javax.mail.internet.MimeMultipart.writeTo(MimeMultipart.java:548)
at com.sun.mail.handlers.multipart_mixed.writeTo(multipart_mixed.java:81)
... 45 more

... 45 more
解决思路:
1.在cn.bing.com上搜索,问题原因是没有设置邮件内容,导致报该错误,其实和发送附件没有任何关系
参考文章:https://stackoverflow.com/questions/32306928/sending-emails-with-attachments-empty-
multipart

问题6:
无报错信息

解决思路:

1.检查代码,具体代码如下:

public boolean sendInlineMail(String fromPos, String toPos, String subject, FileSystemResource file)
{
MimeMessage msg = mailSender.createMimeMessage();
try
{
//MimeMessageHelper构造器,如果要发送附件邮件,必须指定multipart参数为true
MimeMessageHelper helper = new MimeMessageHelper(msg, true);
helper.setFrom(fromPos);
helper.setTo(toPos);
helper.setSubject(subject);
helper.setText("<html><body>静态资源:<img src='cid:pic' /></body></html>", true);
helper.addInline("pic", file);
mailSender.send(msg);
}
catch (MessagingException e)
{
logger.error("发送附件邮件失败.", e);
return false;
} return true;
}

2.对代码进行了调整:将addInline方法要放在setText后面,进行测试发现正常了,可能原因是顺序如果不对,导致资源没有被正确引用。

原文链接:遵循 CC 4.0 BY-SA 版权协议,https://blog.csdn.net/ignorewho/article/details/80654201

【转载】SpringBoot-配置发送邮件遇到的一些问题的更多相关文章

  1. 使用 SpringBoot 配置发送邮件功能

    1.使用 SpringBoot 配置发送邮件功能 项目总体结构 用户表设计 SET FOREIGN_KEY_CHECKS=0; CREATE DATABASE sample; USE sample; ...

  2. SpringBoot配置发送邮件

    一.导入jar包 <dependency> <groupId>org.springframework.boot</groupId> <artifactId&g ...

  3. 转载 springboot 配置读取

    前言:了解过spring-Boot这个技术的,应该知道Spring-Boot的核心配置文件application.properties,当然也可以通过注解自定义配置文件**.properties的信息 ...

  4. SpringBoot配置属性转载地址

    SpringBoot配置属性系列 SpringBoot配置属性之MVC SpringBoot配置属性之Server SpringBoot配置属性之DataSource SpringBoot配置属性之N ...

  5. zabbix 配置发送邮件报警

    标签:监控/SQLServer/Windows 概述 本篇文章主要介绍如何配置zabbix借助外部邮件进行发送邮件报警,zabbix通过配置文件调用mailx来进行邮件的发送.在Centos6以上的版 ...

  6. SpringBoot基础系列-SpringBoot配置

    原创作品,可以转载,但是请标注出处地址:https://www.cnblogs.com/V1haoge/p/9990680.html SpringBoot基础系列-SpringBoot配置 概述 属性 ...

  7. spring boot 学习(十)SpringBoot配置发送Email

    SpringBoot配置发送Email 引入依赖 在 pom.xml 文件中引入邮件配置: <dependency> <groupId>org.springframework. ...

  8. java springboot+maven发送邮件

    springboot+maven发送邮件 废话不多说直接上代码 1. pom 文件导入jar包 <!--邮件发送--> <dependency> <groupId> ...

  9. SpringBoot配置属性之Server

    SpringBoot配置属性系列 SpringBoot配置属性之MVC SpringBoot配置属性之Server SpringBoot配置属性之DataSource SpringBoot配置属性之N ...

  10. springboot上传文件 & 不配置虚拟路径访问服务器图片 & springboot配置日期的格式化方式 & Springboot配置日期转换器

    1.    Springboot上传文件 springboot的文件上传不用配置拦截器,其上传方法与SpringMVC一样 @RequestMapping("/uploadPicture&q ...

随机推荐

  1. zabbix之自定义告警

    zabbix支持内置的告警类型.email,sms,等 有时候需要自定义类型的. [其他微信,钉钉都差不多方式,只是脚本不一样] 自定义告警类型[自定义邮件] 编写自定义脚本,并测试成功. [脚本需要 ...

  2. Java连接Memcached进行CRUD

    参考这篇博文在本机安装了Memcached 在 Java 中常用的memcached有三个: Memcached Client for Java SpyMemcached XMemcached 这里使 ...

  3. instr和like的使用区别

    1.instr函数 instr函数是一个字符串处理函数,它在Oracle/PLSQL中是返回子字符串在源字符串中的位置,如果在源串中没有找到子串,则返回0. instr函数定义如下: /* * 返回子 ...

  4. WGAN实验环境搭建

    "TensorFlow在Windows上支持Python 3.5.x和3.6.x." 因此,您无法在Windows上使用Python 2.7的tensorflow windows+ ...

  5. servlet多线程安全问题

    Servelet多线程安全问题 原因 一个servlet被实例化一次,当有多个用户访问时,多个线程会访问同一个实例,实例变量就会被不同的用户修改. 简单的案例 新建servlet,访问http://l ...

  6. 全国计算机等级考试二级教程2019年版——Python语言程序设计参考答案

    第二章 Python语言基本语法元素 一.选择题C B B C A D B A D B二.编程题1.获得用户输入的一个整数N,计算并输出N的32次方.在这里插入图片描述2.获得用户输入的一段文字,将这 ...

  7. I am a legend: Hacking Hearthstone with machine-learning Defcon talk wrap-up

    I am a legend: Hacking Hearthstone with machine-learning Defcon talk wrap-up: video and slides avail ...

  8. ybatis 逆向工程 自动生成的mapper文件没有 主键方法

    1.数据表没有设置主键 设置个主键就好 2.在mybits配置文档里设置了某些属性值为false 在mybatis配置文档里查看 enableSelectByPrimaryKey="true ...

  9. Qt编写自定义控件28-颜色滑块面板

    一.前言 相比于上一个颜色按钮面板,此控件就要难很多,颜色值有三种表示形式,除了程序员最常用的RGB以外,还有HSB和CMY方式. RGB色彩模式是工业界的一种颜色标准,是通过对红(R).绿(G).蓝 ...

  10. PAT 甲级 1021 Deepest Root (25 分)(bfs求树高,又可能存在part数part>2的情况)

    1021 Deepest Root (25 分)   A graph which is connected and acyclic can be considered a tree. The heig ...