当前位置:网站首页>Alicloud: could not connect to SMTP host: SMTP 163.com, port: 25

Alicloud: could not connect to SMTP host: SMTP 163.com, port: 25

2022-04-23 20:13:00 My brother is not strong enough to fight

Problem description :

I wrote a monitoring program myself , adopt javamail Send monitoring information , When deployed to service execution, an error is reported :

javax.mail.MessagingException: Could not connect to SMTP host: smtp.163.com, port: 25;

DEBUG SMTP: trying to connect to host "smtp.163.com", port 25, isSSL false
javax.mail.MessagingException: Could not connect to SMTP host: smtp.163.com, port: 25;
  nested exception is:
        java.net.ConnectException: Connection timed out (Connection timed out)
        at com.sun.mail.smtp.SMTPTransport.openServer(SMTPTransport.java:1961)
        at com.sun.mail.smtp.SMTPTransport.protocolConnect(SMTPTransport.java:654)
        at javax.mail.Service.connect(Service.java:295)
        at javax.mail.Service.connect(Service.java:176)
        at javax.mail.Service.connect(Service.java:196)
        at com.sonkwo.bi.quartz.util.EmailUtils.sendEmail(EmailUtils.java:108)
        at com.sonkwo.bi.quartz.task.RyTask.toSendCheckSyncData(RyTask.java:109)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)

mean : The server could not pass host: smtp.163.com, port: 25 Connect

By hand telnet verification , Really can't connect

telnet smtp.163.com 25
Trying 220.181.15.161...

There are two solutions :

  1. Unseal 25 Port no. ( Not recommended );
  2. Use other ports (465 Port no. , recommend ).

I remind of it , Doing it azkaban I encountered this problem when sending email notification , Finally, by recompiling azkaban Source code , Only then 25 Port changed to 465 port , Specific view :【(21 Bar message ) Azkaban recompile , solve :Could not connect to SMTP host: smtp.163.com, port: 465【2022 year 01 month 10 Japan 】_ The blog of brother Xiaoqiang who can't die -CSDN Blog

Final solution :

modify javamail Port number in , Add the following code :

// PS:  Some mailbox servers require  SMTP  Connection needs to use  SSL  Safety certification  ( To improve safety ,  Mailbox support SSL Connect ,  You can open it yourself ),
        //      If you can't connect to the mail server ,  Check the console print carefully  log,  If there is something similar  “ The connection fails ,  requirement  SSL  A secure connection ”  Such mistakes ,
        //      Open up below  /* ... */  Comment code between ,  Turn on  SSL  A secure connection .
        /*
        // SMTP  The port of the server  ( Not  SSL  The port of the connection is usually... By default  25,  Can not add ,  If it's on  SSL  Connect ,
        //                   It needs to be changed to  SMTP  The port of the server ,  For details, please refer to the help of the corresponding mailbox service ,
        //                  QQ Mailbox SMTP(SLL) Port is 465 or 587,  Check other mailboxes by yourself )
        final String smtpPort = "465";
        props.setProperty("mail.smtp.port", smtpPort);
        props.setProperty("mail.smtp.socketFactory.class", "javax.net.ssl.SSLSocketFactory");
        props.setProperty("mail.smtp.socketFactory.fallback", "false");
        props.setProperty("mail.smtp.socketFactory.port", smtpPort);

The problem is finally solved , The mail went off smoothly ...

ps: If you want to get javamail Source code , Please see 【(21 Bar message ) adopt javaMail Send E-mail _ The blog of brother Xiaoqiang who can't die -CSDN Blog

版权声明
本文为[My brother is not strong enough to fight]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204210556213720.html

随机推荐