使用JavaMail API发送邮件失败(二)

时间:2022-11-27 19:03:28

我本来打算登录上我的163邮箱,然后冒充某人给别人发邮件,但是发现报如下错误:

com.sun.mail.smtp.SMTPSendFailedException: 553 Mail from must equal authorized user
;
nested exception is:
com.sun.mail.smtp.SMTPSenderFailedException: 553 Mail from must equal authorized user

at com.sun.mail.smtp.SMTPTransport.issueSendCommand(SMTPTransport.java:2133)
at com.sun.mail.smtp.SMTPTransport.mailFrom(SMTPTransport.java:1630)
at com.sun.mail.smtp.SMTPTransport.sendMessage(SMTPTransport.java:1132)
at cn.itcast.demo.SendMail.main(SendMail.java:35)
Caused by: com.sun.mail.smtp.SMTPSenderFailedException: 553 Mail from must equal authorized user

at com.sun.mail.smtp.SMTPTransport.mailFrom(SMTPTransport.java:1637)
... 2 more
Exception in thread "main" com.sun.mail.smtp.SMTPSendFailedException: 553 Mail from must equal authorized user
;
nested exception is:
com.sun.mail.smtp.SMTPSenderFailedException: 553 Mail from must equal authorized user

at com.sun.mail.smtp.SMTPTransport.issueSendCommand(SMTPTransport.java:2133)
at com.sun.mail.smtp.SMTPTransport.mailFrom(SMTPTransport.java:1630)
at com.sun.mail.smtp.SMTPTransport.sendMessage(SMTPTransport.java:1132)
at cn.itcast.demo.SendMail.main(SendMail.java:35)
Caused by: com.sun.mail.smtp.SMTPSenderFailedException: 553 Mail from must equal authorized user

at com.sun.mail.smtp.SMTPTransport.mailFrom(SMTPTransport.java:1637)
... 2 more

产生错误的原因: 由于在做邮件发送时,登录用户和发信人必须一致;而在测试时我登录用户的邮箱是163邮箱,发信人邮箱是QQ邮箱,导致报错。
那该怎么解决呢?解决办法: 保证登录人邮箱跟发信人邮箱一致,要么都用163邮箱,要么都用QQ邮箱。