javax.mail.AhenticationFailedException: 535 Err / A secure connection is requiered(java发邮件)
来源:互联网 发布:淘宝商品质量有问题 编辑:程序博客网 时间:2024/06/02 05:29
Java发邮件的几种方式:
JavaMail
Commons Email
Spring Mail
实验场景: Spring Mail、Web Project
具体描述:
邮件服务器: smtp.qq.com (QQ)
框架: Spring
jar包:
- Spring.jar( 多个jar包,集合)
- mail-1.4.7.jar (版本自选)
- commons-logging-1.2.jar(打印日志信息,同上)
- 运行结果:
- 打印日志信息如下(xml中设置):
DEBUG SMTP: Found extension "PIPELINING", arg ""DEBUG SMTP: Found extension "SIZE", arg "73400320"DEBUG SMTP: Found extension "AUTH", arg "LOGIN PLAIN"DEBUG SMTP: Found extension "AUTH=LOGIN", arg ""DEBUG SMTP: Found extension "MAILCOMPRESS", arg ""DEBUG SMTP: Found extension "8BITMIME", arg ""DEBUG SMTP: Attempt to authenticate using mechanisms: LOGIN PLAIN DIGEST-MD5 NTLM DEBUG SMTP: AUTH LOGIN command trace suppressedDEBUG SMTP: AUTH LOGIN failedException in thread "main" org.springframework.mail.MailAuthenticationException: Authentication failed; nested exception is javax.mail.AuthenticationFailedException: 535 Error: ÇëʹÓÃÊÚȨÂëµÇ¼¡£ÏêÇéÇë¿´: http://service.mail.qq.com/cgi-bin/help?subtype=1&&id=28&&no=1001256 at org.springframework.mail.javamail.JavaMailSenderImpl.doSend(JavaMailSenderImpl.java:392) at org.springframework.mail.javamail.JavaMailSenderImpl.send(JavaMailSenderImpl.java:306) at org.springframework.mail.javamail.JavaMailSenderImpl.send(JavaMailSenderImpl.java:296) at mail.SpringSimpleMailTest.main(SpringSimpleMailTest.java:35)Caused by: javax.mail.AuthenticationFailedException: 535 Error: ÇëʹÓÃÊÚȨÂëµÇ¼¡£ÏêÇéÇë¿´: http://service.mail.qq.com/cgi-bin/help?subtype=1&&id=28&&no=1001256 at com.sun.mail.smtp.SMTPTransport$Authenticator.authenticate(SMTPTransport.java:826) at com.sun.mail.smtp.SMTPTransport.authenticate(SMTPTransport.java:761) at com.sun.mail.smtp.SMTPTransport.protocolConnect(SMTPTransport.java:685) at javax.mail.Service.connect(Service.java:295) at org.springframework.mail.javamail.JavaMailSenderImpl.doSend(JavaMailSenderImpl.java:389) ... 3 more
一开始,尝试使用 smtp.163.com(网易),抛出类似的错误,由于问题源于一个开源项目的研究,可能对其进行了封装,调试了很久,只能解决部分问题。 。。。 查阅了一些资料,邮件发送成功,此类相关问题应该就能迎刃而解!
原因如下:
服务 授权码
正确配置邮件发送相关信息
Web Project 项目结构:
project name:TestMail
package name : mail
file : 3 个
- RT:
- SpringSimpleMailTest.java
package mail;import org.springframework.context.ApplicationContext;import org.springframework.context.support.ClassPathXmlApplicationContext;import org.springframework.mail.MailSender;import org.springframework.mail.SimpleMailMessage;/** * @ClassName: SpringSimpleMailTest * * @Description: TODO Spring 实现简单的邮件发送测试 * * @author kngines * * @date 2017年5月6日 */public class SpringSimpleMailTest { public static void main(String[] args) { // 创建应用程序上下文 ApplicationContext actx = new ClassPathXmlApplicationContext("mail/mailMessage.xml"); // Spring 封装MailSender,不再重复造轮子 MailSender ms = (MailSender) actx.getBean("mailSender"); // 简单邮件发送 SimpleMailMessage smm = (SimpleMailMessage) actx.getBean("mailMessage"); // 主题,内容 smm.setSubject("你好"); smm.setText("这个是一个通过Spring框架来发送邮件的小程序"); // 发送 ms.send(smm); }}
- mail.properties
#-------------------------------------# 邮件服务配置#-------------------------------------# 服务器mail.host=smtp.qq.com# 端口号 qq邮箱需要使用SSL 端口号465或587mail.smtp.port=465# 服务器超时时间mail.smtp.timeout=50000# starttls 是对纯文本通信协议的扩展。它提供一种方式将纯文本连接升级为加密连接(TLS或SSL)mail.smtp.starttls.enable=true# 开启控制台打印服务器相应信息(日志)mail.debug=true# 登录用户名,如果是qq,则填写qq号mail.username=123456# 授权码(例如,qq 开启 SMTP 授权码,qq授权码16位)mail.password=xzbasdjfadladsfa# 是否需要验证码mail.smtp.auth=true# 发件人地址(qq邮箱 A)mail.from=123456@qq.com# 收件人地址(qq邮箱 B)mail.to=9876543@qq.com
- mailMessage.xml
<?xml version="1.0" encoding="UTF-8" ?><beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd" xmlns:aop="http://www.springframework.org/schema/aop" xmlns:p="http://www.springframework.org/schema/p"> <!-- 加载Properties文件 --> <bean id="configurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"> <property name="locations"> <list> <value>classpath:/mail/mail.properties</value> </list> </property> </bean> <!-- 申明SimpleMailMessage对象 --> <bean id="mailMessage" class="org.springframework.mail.SimpleMailMessage"> <property name="from"> <value>${mail.from}</value> </property> <!-- 设置接收方 --> <property name="to" value="${mail.to}" /> <!-- 查看SimpleMailMessage源码还可以注入标题,内容等 --> </bean> <!-- 声明 JavaMailSenderImpl对象 --> <bean id="mailSender" class="org.springframework.mail.javamail.JavaMailSenderImpl"> <property name="defaultEncoding" value="UTF-8" /> <property name="host" value="${mail.host}" /> <property name="username" value="${mail.username}" /> <property name="password" value="${mail.password}" /> <property name="javaMailProperties"> <props> <prop key="mail.smtp.auth">${mail.smtp.auth}</prop> <prop key="mail.debug">${mail.debug}</prop> <prop key="mail.smtp.timeout">${mail.smtp.timeout}</prop> <prop key="mail.smtp.starttls.enable">${mail.smtp.starttls.enable}</prop> <prop key="mail.smtp.socketFactory.class">javax.net.ssl.SSLSocketFactory</prop> <prop key="mail.smtp.socketFactory.port">${mail.smtp.port}</prop> <prop key="mail.smtp.socketFactory.fallback">false</prop> </props> </property> </bean></beans>
根据步骤建立Web Project 、导入jar包之后,检查 客户端授权码、端口是否配置(密码不是登录邮箱时的真实密码)。
成功运行结果如下:
DEBUG SMTP: Found extension "PIPELINING", arg ""DEBUG SMTP: Found extension "SIZE", arg "73400320"DEBUG SMTP: Found extension "AUTH", arg "LOGIN PLAIN"DEBUG SMTP: Found extension "AUTH=LOGIN", arg ""DEBUG SMTP: Found extension "MAILCOMPRESS", arg ""DEBUG SMTP: Found extension "8BITMIME", arg ""DEBUG SMTP: STARTTLS requested but already using SSLDEBUG SMTP: Attempt to authenticate using mechanisms: LOGIN PLAIN DIGEST-MD5 NTLM DEBUG SMTP: AUTH LOGIN command trace suppressedDEBUG SMTP: AUTH LOGIN succeededDEBUG SMTP: use8bit falseMAIL FROM:<1234567@qq.com>250 OkRCPT TO:<3147755101@qq.com>250 OkDEBUG SMTP: Verified AddressesDEBUG SMTP: 3147755101@qq.comDATA354 End data with <CR><LF>.<CR><LF>Date: Sat, 6 May 2017 20:10:20 +0800 (CST)From: 123456@qq.comTo: 9876543@qq.comMessage-ID: <857394605.0.1494072621026.JavaMail.Khgines@Kngines-PC>Subject: =?UTF-8?B?5L2g5aW9?=MIME-Version: 1.0Content-Type: text/plain; charset=UTF-8Content-Transfer-Encoding: base646L+Z5Liq5piiA5Liq6YCa6L+HU5qGG5p6l5Y+R6Ku5E5bCP56iL5bqP.250 Ok: queued as QUIT221 Bye
References:
Java发邮件-QQ服务器认证(A secure connection is requiered(such as ssl))
使用Spring的JAVA Mail支持简化邮件发送
- spring 配置 java mail 发送邮件
0 0
- javax.mail.AhenticationFailedException: 535 Err / A secure connection is requiered(java发邮件)
- javax.mail.AuthenticationFailedException: 530 Error: A secure connection is requiered
- javax.mail.AuthenticationFailedException: 530 Error: A secure connection is requiered
- Java发邮件-QQ服务器认证(A secure connection is requiered(such as ssl))
- Java发邮件-QQ服务器认证(A secure connection is requiered(such as ssl))
- Java发邮件-QQ服务器认证(A secure connection is requiered(such as ssl))
- Java之——发邮件-QQ服务器认证(A secure connection is requiered(such as ssl))
- javax.mail.AuthenticationFailedException: 530 Error: A secure connection is requiered(such as ssl).
- 用Python发邮件,QQ邮件,解决(Error: A secure connection is requiered(such as ssl))
- Java发邮件测试,QQ总是出现错误A secure connection is requiered(such as ssl). More information at
- 用qq邮箱做服务器发邮件失败,530 A secure connection is requiered(such as ssl)后解决方案如下
- Java HtmlEmail 使用QQ邮箱发送邮件报错 530 Error: A secure connection is requiered(such as ssl)
- 530 A secure connection is requiered(such as ssl)
- 530 Error: A secure connection is requiered(such as ssl).
- 530 A secure connection is requiered(such as ssl)
- A secure connection is requiered(such as ssl). More information at http://service.mail.qq.com/cgi-bi
- 530 Error: A secure connection is requiered(such as ssl). More information at http://service.mail.qq
- 530 Error: A secure connection is requiered(such as ssl). More information at http://service.mail.qq
- SEO拽写文章优化技巧
- mybatis的动态sql-if和sql片段 foreach的使用
- [HDU](2098)分拆素数和---穷举法和哥德巴赫猜想
- 原创jquery插件treeTable(转)
- p3422最小费最大流(未解决)
- javax.mail.AhenticationFailedException: 535 Err / A secure connection is requiered(java发邮件)
- 基于空间相关的图像模板匹配及MATLAB实现
- redis集群和安装
- 算法学习笔记--狄克斯特拉算法
- PaxosLease:实现租约的无盘Paxos算法
- java中异常的使用及注意事项
- 常见设计模式的应用场景
- Python入门学习之operator--操作符函数
- 手机联系人的读取和插入