com.sun.mail.smtp.SMTPSendFailedException: 530 5.7.57 SMTP; Client was not authenticated to send ano

The following are the errors that occur when using office365

My configuration:



#email
#SMTP服务器的名字
spring.mail.host=xxxx
#发送人邮箱名称
spring.mail.username=xxxx
#邮箱密码,这里指的是,在邮箱中打开SMTP/POP3验证之后,会给出一个验证码
spring.mail.password =xxxx
#编码格式
spring.mail.default-encoding=UTF-8
#SMTP服务器开放的端口
spring.mail.port=587
spring.mail.properties.mail.smtp.socketFactory.class=javax.net.ssl.SSLSocketFactory
spring.mail.properties.mail.smtp.socketFactory.fallback=true
spring.mail.properties.mail.smtp.starttls.enable=true

 


The following error is reported when using java to call Office365 to send mail:   

  com.sun.mail.smtp.SMTPSendFailedException: 530 5.7.57 SMTP; Client was not authenticated to send anonymous mail during MAIL FROM

    at com.sun.mail.smtp.SMTPTransport.issueSendCommand(SMTPTransport.java:2108)
    at com.sun.mail.smtp.SMTPTransport.mailFrom(SMTPTransport.java:1609)
    at com.sun.mail.smtp.SMTPTransport.sendMessage(SMTPTransport.java:1117)
    at javax.mail.Transport.send0(Transport.java:195)
    at javax.mail.Transport.send(Transport.java:124)
    at com.paraview.mail.MailSender.sendTextMail(MailSender.java:60)
    at com.paraview.mail.Test.main(Test.java:10)

 

   The mailbox configuration is as follows:

    SMTP settings

    Server name: smtp.outlook.cn

   Port: 587

    Encryption method: TLS

  I can send and receive emails normally after configuring through Foxmail. Why can't I use the code?

  From the mailbox configuration, I can see the encryption method: TLS, TLS is not SSL, so I added the configuration proper.put("mail.smtp.starttls.enable", "true");

 Then continue to run and find that the error is different

Why is this mistake? The connection cannot be established via TLS, but it is obviously TLS. There are some blogs on the Internet saying that it must be jdk1.6 and not jdk1.7. Although I don’t understand why, I simply changed the jdk version.

The result is still wrong!

At this time, I simply wanted to add all the configurations to see what effect, so I added the following configuration:

proper.put("mail.smtp.socketFactory.class","javax.net.ssl.SSLSocketFactory");
proper.put("mail.smtp.socketFactory.port","587");
        proper.put("mail.smtp.socketFactory.fallback", "false"); 

At this time, the error changed again: Could not connect to SMTP host: smtp.partner.outlook.cn, port: 587;

  So I added the configuration:

      MailSSLSocketFactory sf = new MailSSLSocketFactory(); 
      sf.setTrustAllHosts(true); 
proper.put("mail.smtp.ssl.socketFactory", sf);

The error remains! At this time, I am unable to complain, continue to check, there is an error in the error is this:

Caused by: javax.net.ssl.SSLException: Unrecognized SSL message, plaintext connection?

What's wrong with this?

So I asked Du Niang again, but Du Niang said that this configuration mail.smtp.socketFactory.fallback should be changed to true.

So I changed the configuration proper.put("mail.smtp.socketFactory.fallback", "true"); 
 

Guess you like

Origin blog.csdn.net/qq_39313596/article/details/103348596