Java Mail发送邮件java.lang.IllegalStateException: Can't overwrite cause错误

使用java mail发送邮件,配置多个smtp账户循环发送。其中一个账户能发送成功,其他账户都发送失败,出现如下错误:

java.lang.IllegalStateException: Can't overwrite cause
	at java.lang.Throwable.initCause(Unknown Source)
	at javax.mail.MessagingException.setNextException(MessagingException.java:51)
	at com.sun.mail.smtp.SMTPTransport.mailFrom(SMTPTransport.java:1625)
	at com.sun.mail.smtp.SMTPTransport.sendMessage(SMTPTransport.java:1119)

找了半天也不知道啥原因。后来注意到,在session创建的时候,使用的是

public static Session getDefaultInstance(Properties props,
                                         Authenticator authenticator)

API中有一段说明:

Note also that the Properties object is used only the first time this method is called, when a new Session object is created. Subsequent calls return the Session object that was created by the first call, and ignore the passed Properties object. Use the getInstance method to get a new Session object every time the method is called.

就是properties只初始化一次,以后都用同一个。据此,改用getInstance替代 getDefaultInstance,问题依旧。加Debug,发现如下错误:

DEBUG SMTP: Found extension "PIPELINING", arg ""
DEBUG SMTP: Found extension "SIZE", arg "52428800"
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
DEBUG SMTP: check mechanisms: LOGIN PLAIN DIGEST-MD5 NTLM 
DEBUG SMTP: AUTH LOGIN command trace suppressed
DEBUG SMTP: AUTH LOGIN succeeded
DEBUG SMTP: use8bit false
MAIL FROM:<abccc@qxqpw.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
原来是发件人填错了
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值