您现在的位置是:网站首页 > 代码编程 > JAVA开发JAVA开发

【原】使用Java发送邮件时碰到了一个501错误

不忘初心 不忘初心 2019-04-14 围观() 评论() 点赞() JAVA开发

简介:QQ邮箱、新浪邮箱、网易邮箱,使用Java进行邮件发送时,基本上都是一模一样的逻辑,就是mail.smtp.host的配置有区别,大家在使用的时候,可以将公共代码抽离出来,将那些配置用参数的方式传过去。在实现过程中,没有其他的什么大问题,倒是碰到了一个501错误:具体错误信息如下:DEBUG:JavaMailversion1.6.2DEBUG:successfullyloadedresource:

QQ邮箱、新浪邮箱、网易邮箱,使用Java进行邮件发送时,基本上都是一模一样的逻辑,就是mail.smtp.host的配置有区别,大家在使用的时候,可以将公共代码抽离出来,将那些配置用参数的方式传过去。

在实现过程中,没有其他的什么大问题,倒是碰到了一个501错误:

使用Java发送邮件时碰到了一个501错误

具体错误信息如下:

DEBUG: JavaMail version 1.6.2
DEBUG: successfully loaded resource: /META-INF/javamail.default.address.map
DEBUG: getProvider() returning javax.mail.Provider[TRANSPORT,smtp,com.sun.mail.smtp.SMTPTransport,Oracle]
DEBUG SMTP: useEhlo true, useAuth true
DEBUG SMTP: trying to connect to host "smtp.qq.com", port 465, isSSL true
220 smtp.qq.com Esmtp QQ Mail Server
DEBUG SMTP: connected to host "smtp.qq.com", port: 465
EHLO LAPTOP-UTR4AS7N
250-smtp.qq.com
250-PIPELINING
250-SIZE 73400320
250-AUTH LOGIN PLAIN
250-AUTH=LOGIN
250-MAILCOMPRESS
250 8BITMIME
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: protocolConnect login, host=smtp.qq.com, user=111111111@qq.com, password=<non-null>
DEBUG SMTP: Attempt to authenticate using mechanisms: LOGIN PLAIN DIGEST-MD5 NTLM XOAUTH2 
DEBUG SMTP: Using mechanism LOGIN
DEBUG SMTP: AUTH LOGIN command trace suppressed
DEBUG SMTP: AUTH LOGIN succeeded
DEBUG SMTP: use8bit false
MAIL FROM:<xxx@qq.com>
501 mail from address must be same as authorization user
DEBUG SMTP: got response code 501, with response: 501 mail from address must be same as authorization user

RSET
250 Ok
DEBUG SMTP: MessagingException while sending, THROW: 
com.sun.mail.smtp.SMTPSendFailedException: 501 mail from address must be same as authorization user
;
  nested exception is:
	com.sun.mail.smtp.SMTPSenderFailedException: 501 mail from address must be same as authorization user

	at com.sun.mail.smtp.SMTPTransport.issueSendCommand(SMTPTransport.java:2358)
	at com.sun.mail.smtp.SMTPTransport.mailFrom(SMTPTransport.java:1823)
	at com.sun.mail.smtp.SMTPTransport.sendMessage(SMTPTransport.java:1300)
	at com.wolffy.reader.util.MailUtil.sendQQEmail(MailUtil.java:48)
	at com.wolffy.reader.util.MailUtil.main(MailUtil.java:56)
Caused by: com.sun.mail.smtp.SMTPSenderFailedException: 501 mail from address must be same as authorization user

	at com.sun.mail.smtp.SMTPTransport.mailFrom(SMTPTransport.java:1832)
	... 3 more
23:02:08.457 [main] ERROR com.wolffy.reader.util.MailUtil - 发送QQ邮件失败:com.sun.mail.smtp.SMTPSendFailedException: 501 mail from address must be same as authorization user
;
  nested exception is:
	com.sun.mail.smtp.SMTPSenderFailedException: 501 mail from address must be same as authorization user

	at com.sun.mail.smtp.SMTPTransport.issueSendCommand(SMTPTransport.java:2358)
	at com.sun.mail.smtp.SMTPTransport.mailFrom(SMTPTransport.java:1823)
	at com.sun.mail.smtp.SMTPTransport.sendMessage(SMTPTransport.java:1300)
	at com.wolffy.reader.util.MailUtil.sendQQEmail(MailUtil.java:48)
	at com.wolffy.reader.util.MailUtil.main(MailUtil.java:56)
Caused by: com.sun.mail.smtp.SMTPSenderFailedException: 501 mail from address must be same as authorization user

	at com.sun.mail.smtp.SMTPTransport.mailFrom(SMTPTransport.java:1832)
	... 3 more

查阅资料后,让我啼笑皆非!

竟然是自己手误将from参数写错了,发送者必须要和SMTP中的账号一致

// 设置发件人邮箱地址
message.setFrom(new InternetAddress("xxx@qq.com"));

要与connect保持一致,connect中是xxx@qq.com,那么from中也必须是xxx@qq.com

// 连接自己的邮箱账户
transport.connect(sender, password);// 密码为QQ邮箱开通的SMTP服务后得到的客户端授权码

java发邮件

看完文章,有任何疑问,请加入群聊一起交流!!!

很赞哦! ()

文章评论

  • 请先说点什么
    人参与,条评论

请使用电脑浏览器访问本页面,使用手机浏览器访问本页面会导致下载文件异常!!!

雨落无影

关注上方公众号,回复关键字【下载】获取下载码

用完即删,每次下载需重新获取下载码

若出现下载不了的情况,请及时联系站长进行解决

站点信息

  • 网站程序:spring + freemarker
  • 主题模板:《今夕何夕》
  • 文章统计:篇文章
  • 标签管理标签云
  • 微信公众号:扫描二维码,关注我们