首页   >   代码编程

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

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服务后得到的客户端授权码

QQ群Ⅰ: 686430774 (已满)

QQ群Ⅱ: 718410762 (已满)

QQ群Ⅲ: 638620451 (已满)

QQ群Ⅳ: 474195684

如果文章有帮到你,可以考虑请博主喝杯咖啡!

分享到:

欢迎分享本文,转载请注明出处!

作者:不忘初心

发布时间:2019-04-14

永久地址:https://www.jiweichengzhu.com/article/3772687196874b7e88e1640a0451bece

评论