有时登录有时不通过JavaMail

时间:2017-06-28 13:21:28

标签: java email debugging javamail

我有随机登录失败的问题。一小时发生2-4次,类似的时间,例如:大约14:26,14:48,15:26,15:49等。

我使用JavaMail(版本1.5.6)进行电子邮件处理。邮箱是Microsoft Exchange 应用程序每5分钟运行一次以连接到邮箱。

电子邮件处理的伪代码:

 estabilishConncetion()
 prepareMailbox()
 downloadEmails()
 moveEmailsToSOmething()
 closeConnection()

代码连接是这样的:

 public void establishConnection() throws ConnectionException {
    logger.info("Establish connection... ");
    props = new Properties();

    props.setProperty("mail.imaps.ssl.enable", "true");
    props.setProperty("mail.imaps.port", 993);
    props.setProperty("mail.imaps.timeout", 60000);
    props.setProperty("mail.imaps.connectiontimeout",60000 );

    props.put("mail.imaps.auth.plain.disable", "true");
    props.put("mail.imaps.auth.ntlm.disable", "true");
    props.put("mail.imaps.auth.gssapi.disable", "true");        
    props.setProperty("mail.debug", "true"); // only for test

    Session session = Session.getInstance(props, new Authenticator(){
        @Override
        protected PasswordAuthentication getPasswordAuthentication() {
            return new PasswordAuthentication(somename, somepassword);
        }
    });

    try {
        store = session.getStore("imaps");
        store.connect(EmailServerAddress, EmailAddress,Password);
    } catch (MessagingException e) {
        throw new ConnectionException(" Problem occured when try connect to host: " + ServerAddress + " on address: " +EmailAddress);
    }
    logger.info("Connected to mailbox.");
}

连接时记录:

  

DEBUG IMAPS:尝试连接主机“somehost”,端口993,isSSL true]]

     

*确定Microsoft Exchange IMAP4服务已准备就绪。]]

     

A0能力]]

     

*功能IMAP4 IMAP4rev1 AUTH = NTLM AUTH = GSSAPI AUTH = PLAIN   STARTTLS UIDPLUS儿童空闲NAMESPACE LITERAL +]]

     

A0 OK CAPABILITY已完成。]]

     

DEBUG IMAPS:protocolConnect登录,host = somehost,   user = someuser,password =]]

     

DEBUG IMAPS:服务器不支持机制LOGIN]] DEBUG IMAPS:   LOGIN命令跟踪被抑制]] DEBUG IMAPS:LOGIN命令结果:A1   OK LOGIN已完成。]]

     

A2能力]] *能力IMAP4 IMAP4rev1 AUTH = NTLM AUTH = GSSAPI   AUTH = PLAIN STARTTLS UIDPLUS CHILDREN IDLE NAMESPACE LITERAL +]]

     

A2 OK CAPABILITY已完成。]]

     

DEBUG IMAPS:AUTH:NTLM]]已连接到邮箱。]]

未连接时记录:

  

DEBUG IMAPS:尝试连接到主机“somehost”,端口993,isSSL   真]]

     

*确定Microsoft Exchange IMAP4服务已准备就绪。]]

     

A0能力]]

     

*功能IMAP4 IMAP4rev1 AUTH = NTLM AUTH = GSSAPI AUTH = PLAIN   STARTTLS UIDPLUS儿童空闲NAMESPACE LITERAL +]]

     

A0 OK CAPABILITY已完成。]]

     

DEBUG IMAPS:protocolConnect登录,host = somehost,user = someuser,   密码=]]

     

DEBUG IMAPS:服务器不支持机制LOGIN]] DEBUG   IMAPS:LOGIN命令跟踪被抑制]] DEBUG IMAPS:LOGIN命令   结果:A1 NO LOGIN失败。]] //尝试再次登录   失败

我在我的代码中检查了这个和它的确定: 1. Using JavaMail to connect to IMAP getting "A1 NO LOGIN failed" exception 2. https://javaee.github.io/javamail/FAQ#Exchange-login 3.我通过连接进行了单元测试,并且总是通过

任何解决方案,线索,如何更好地调试这个? :)

0 个答案:

没有答案