开发者社区> 问答> 正文

阿里云服务器ECS中Java应用访问阿里云邮箱提示连接超时

有个Java项目(基于SpringBoot开发),在我本地可以正常访问阿里云邮箱(个人版,通过JavaMail客户端访问邮箱服务器,收取邮件),并且我本地运行时是将项目打成war包并且部署到tomcat容器里运行。但是相同的war包部署到阿里云的机器上,有如下提示:
javax.mail.MessagingException: 连接超时 (Connection timed out)                    
        at com.sun.mail.imap.IMAPStore.protocolConnect(IMAPStore.java:670)        
        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 studio.tony.review.console.service.backend.CollectReviewTask.run(Collect
ReviewTask.java:63)                                                                
        at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
        at java.util.concurrent.FutureTask.runAndReset(FutureTask.java:308)        
        at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.acc
ess$301(ScheduledThreadPoolExecutor.java:180)                                      
        at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run
(ScheduledThreadPoolExecutor.java:294)                                            
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.jav
a:1142)                                                                            
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.ja
va:617)                                                                            
        at java.lang.Thread.run(Thread.java:745)                                  
Caused by: java.net.ConnectException: 连接超时 (Connection timed out)              
        at java.net.PlainSocketImpl.socketConnect(Native Method)                  
        at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:
350)                                                                              
        at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImp
l.java:206)                                                                        
        at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:18
8)                                                                                
        at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)              
        at java.net.Socket.connect(Socket.java:589)                                
        at java.net.Socket.connect(Socket.java:538)                                
        at com.sun.mail.util.SocketFetcher.createSocket(SocketFetcher.java:299)    
        at com.sun.mail.util.SocketFetcher.getSocket(SocketFetcher.java:234)      
        at com.sun.mail.iap.Protocol.<init>(Protocol.java:116)                    
        at com.sun.mail.imap.protocol.IMAPProtocol.<init>(IMAPProtocol.java:115)  
        at com.sun.mail.imap.IMAPStore.newIMAPProtocol(IMAPStore.java:685)        
        at com.sun.mail.imap.IMAPStore.protocolConnect(IMAPStore.java:636)


展开
收起
koalton 2017-11-17 23:24:30 4439 0
2 条回答
写回答
取消 提交回答
  • 回 1楼dongshan8的帖子
    版主大神好,您提到的25端口应该是使用SMTP协议发送邮件使用25端口,现在我的场景是使用IMAP协议接收邮件,使用JavaMail在进行IMAP协议接收邮件时,并不会使用25端口(至少从程序上看是没有使用到端口的,且在我本地验证通过)。
    另外您提到的ECS实例都过滤了25端口通讯,我在系统服务里的防火墙中已经对25端口设置了通行授权(进站和出站都设置了允许)

    叨扰大神,可以再帮忙分析下吗?

    -------------------------

    回 3楼dongshan8的帖子
    访问目标端口有如下提示:
    [root@koalton ~]# ssh -v -p 143 12@imap.aliyun.com                                                                                                                          
    OpenSSH_6.6.1, OpenSSL 1.0.1e-fips 11 Feb 2013                                                                                                                              
    debug1: Reading configuration data /etc/ssh/ssh_config                                                                                                                      
    debug1: /etc/ssh/ssh_config line 56: Applying options for *                                                                                                                  
    debug1: Connecting to imap.aliyun.com [140.205.94.8] port 143

    一直没有反应,

    -------------------------

    回 5楼dongshan8的帖子
    这就尴尬了。
    我试了下另外网易邮箱的IMAP端口,也是143,结果如下:
    [root@koalton ~]# ssh -v -p 143 12@imap.163.com                                                                                                                              
    OpenSSH_6.6.1, OpenSSL 1.0.1e-fips 11 Feb 2013                                                                                                                              
    debug1: Reading configuration data /etc/ssh/ssh_config                                                                                                                      
    debug1: /etc/ssh/ssh_config line 56: Applying options for *                                                                                                                  
    debug1: Connecting to imap.163.com [123.125.50.47] port 143.                                                                                                                
    debug1: connect to address 123.125.50.47 port 143: Connection timed out                                                                                                      
    ssh: connect to host imap.163.com port 143: Connection timed out

    之前在使用ssh时候,访问阿里云的邮箱服务器(IMAP)时候,后来我看了下结果,也是提示 Connection timed out

    是不是大神我需要设置下我的实例的防火墙?把里面的规则全部清空可以吗?
    2017-11-19 00:00:15
    赞同 展开评论 打赏
  • 旺旺:nectar2。
    版主回复:

    请问您连接的邮箱服务器端口是什么?

    如果是25端口,有可能需要更换到其它的可用端口。因为阿里云新建的ECS实例都过滤了25端口通讯。

    -------------------------

    回 2楼(koalton) 的帖子
    版主回复:

    请问在这个场景中,您是仅收邮件还是收发邮件?

    如果您是使用IMAP协议的,可以尝试在Shell里测试,看是否能连通到目的服务器的143和993端口。

    -------------------------

    回 4楼(koalton) 的帖子
    版主回复:

    同时,测试连接其它的imap服务器,结果是怎么样的呢?

    -------------------------

    回 6楼(koalton) 的帖子
    版主回复:

    您可以尝试在安全组规则里放行所有的协议后,对比测试,看看有没有不同的结果哩。
    2017-11-18 15:43:35
    赞同 展开评论 打赏
问答排行榜
最热
最新

相关电子书

更多
如何运维千台以上游戏云服务器 立即下载
网站/服务器取证 实践与挑战 立即下载
ECS计算与存储分离架构实践 立即下载