Android开发javax.mail适配outlook邮箱发送

先看下报错:

: com.sun.mail.util.MailConnectException: Couldn't connect to host, port: smtp.outlook.com, 465; timeout -1;
2022-08-22 11:26:25.442 15187-15307/com.xbykj.mobilesales W/System.err:   nested exception is:
2022-08-22 11:26:25.442 15187-15307/com.xbykj.mobilesales W/System.err:     java.net.ConnectException: failed to connect to smtp.outlook.com/52.98.33.226 (port 465) from /:: (port 37434): connect failed: ETIMEDOUT (Connection timed out)
2022-08-22 11:26:25.442 15187-15307/com.xbykj.mobilesales W/System.err: at com.sun.mail.smtp.SMTPTransport.openServer(SMTPTransport.java:2210)
2022-08-22 11:26:25.442 15187-15307/com.xbykj.mobilesales W/System.err: at com.sun.mail.smtp.SMTPTransport.protocolConnect(SMTPTransport.java:722)
2022-08-22 11:26:25.442 15187-15307/com.xbykj.mobilesales W/System.err: at javax.mail.Service.connect(Service.java:364)
2022-08-22 11:26:25.442 15187-15307/com.xbykj.mobilesales W/System.err: at javax.mail.Service.connect(Service.java:222)
2022-08-22 11:26:25.442 15187-15307/com.xbykj.mobilesales W/System.err: at javax.mail.Service.connect(Service.java:171)
2022-08-22 11:26:25.442 15187-15307/com.xbykj.mobilesales W/System.err: at javax.mail.Transport.send0(Transport.java:230)
2022-08-22 11:26:25.442 15187-15307/com.xbykj.mobilesales W/System.err: at javax.mail.Transport.send(Transport.java:100)
2022-08-22 11:26:25.442 15187-15307/com.xbykj.mobilesales W/System.err: at com.xbykj.mobilesales.utils.SendEmail.sendEmail(SendEmail.java:196)
2022-08-22 11:26:25.442 15187-15307/com.xbykj.mobilesales W/System.err: at com.xbykj.mobilesales.helper.OrderHelper$1.run(OrderHelper.java:270)
2022-08-22 11:26:25.442 15187-15307/com.xbykj.mobilesales W/System.err: at java.lang.Thread.run(Thread.java:920)
2022-08-22 11:26:25.443 15187-15307/com.xbykj.mobilesales W/System.err: Caused by: java.net.ConnectException: failed to connect to smtp.outlook.com/52.98.33.226 (port 465) from /:: (port 37434): connect failed: ETIMEDOUT (Connection timed out)
2022-08-22 11:26:25.443 15187-15307/com.xbykj.mobilesales W/System.err: at libcore.io.IoBridge.connect(IoBridge.java:188)
2022-08-22 11:26:25.443 15187-15307/com.xbykj.mobilesales W/System.err: at java.net.PlainSocketImpl.socketConnect(PlainSocketImpl.java:142)
2022-08-22 11:26:25.443 15187-15307/com.xbykj.mobilesales W/System.err: at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:390)
2022-08-22 11:26:25.443 15187-15307/com.xbykj.mobilesales W/System.err: at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:230)
2022-08-22 11:26:25.443 15187-15307/com.xbykj.mobilesales W/System.err: at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:212)
2022-08-22 11:26:25.443 15187-15307/com.xbykj.mobilesales W/System.err: at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:436)

关键报错信息: Caused by: java.net.ConnectException: failed to connect to smtp.outlook.com/52.98.33.226 (port 465) from /:: (port 37434): connect failed: ETIMEDOUT (Connection timed out)

居然连接超时,代码和别人的一样啊。

解决方案:把端口改为587即可
case "outlook.com":
            SMTPHost = "smtp.outlook.com";
            SMTPPort = "587";
            break;

已经适配腾讯邮箱和outlook邮箱,也适配了g_mail邮箱,有遇到其他问题的,可以私信或者评论我

你可能感兴趣的:(Android开发javax.mail适配outlook邮箱发送)