简体   繁体   English

java.net.SocketException:读取邮件时连接重置

[英]java.net.SocketException: Connection Reset while Reading Mails

javax.mail.MessagingException: Connection reset; javax.mail.MessagingException:连接重置; nested exception is: java.net.SocketException: Connection reset嵌套异常是:java.net.SocketException: Connection reset

I have a service to read mails from outlook.我有一项服务可以读取来自 outlook 的邮件。 Receiving the above error randomly.随机收到上述错误。 What would be the root cause of this issue.这个问题的根本原因是什么。 Using JAVA 8 and javax.mail-1.6.2 to read mails.使用 JAVA 8 和 javax.mail-1.6.2 来阅读邮件。

Below is my mail settings以下是我的邮件设置

Properties props = new Properties();
props.put("mail.transport.protocol", "smtp");
props.put("mail.smtp.host", "outlook.office365.com"); 
props.put("mail.smtp.socketFactory.port", "587"); 
props.put("mail.smtp.socketFactory.class","javax.net.ssl.SSLSocketFactory");
props.put("mail.smtp.auth", "true"); 
props.put("mail.smtp.port", "587");
props.put("mail.smtp.starttls.enable", "true");

The problem is more likely to be a network issue than an issue with your application.该问题更可能是网络问题,而不是您的应用程序问题。 It might be worth having a look here to see if any of those probable causes are likely or possible in your circumstance.可能值得在这里查看一下,看看在您的情况下是否有任何可能的原因。 Having had a similar issue with outlook previously with no root cause established, mitigation is also an option. outlook 之前遇到过类似问题,但没有确定根本原因,缓解也是一种选择。 Below shows a basic retry mechanism which, in practical terms, eliminated the issue.下面显示了一个基本的重试机制,它实际上消除了这个问题。

            // send email with try-catch loop 
            int count = 0;
            int maxTries = 5;
            while(true) {
                try {
                    // get and set your protocols
                    mailSender.send(message);
                    break;
                } catch (Exception e) {
                    if (++count == maxTries) {
                        // Give up and throw the error
                        throw e;
                    }
                }
            }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM