代码之家  ›  专栏  ›  技术社区  ›  Khalid Imam

从exchange读取邮件的Javamail在本地主机中工作,但在服务器上托管时不工作

  •  0
  • Khalid Imam  · 技术社区  · 11 年前

    当我从本地主机尝试时,我能够成功地使用javamail读取和删除邮件,但当我在服务器上部署java代码并尝试调用服务时,它会在store.connect(pop3Host,user,password)处卡住;

    DEBUG: setDebug: JavaMail version 1.4.7
    DEBUG: getProvider() returning javax.mail.Provider[STORE,pop3s,com.sun.mail.pop3.POP3SSLStore,Oracle]
    DEBUG POP3: mail.pop3s.rsetbeforequit: false
    DEBUG POP3: mail.pop3s.disabletop: false
    DEBUG POP3: mail.pop3s.forgettopheaders: false
    DEBUG POP3: mail.pop3s.cachewriteto: false
    DEBUG POP3: mail.pop3s.filecache.enable: false
    DEBUG POP3: mail.pop3s.keepmessagecontent: false
    DEBUG POP3: mail.pop3s.starttls.enable: false
    DEBUG POP3: mail.pop3s.starttls.required: false
    DEBUG POP3: mail.pop3s.apop.enable: false
    DEBUG POP3: mail.pop3s.disablecapa: false
    DEBUG POP3: connecting to host "hostname", port 995, isSSL true
    
    
    Here are the properties added:
    
        Properties properties = new Properties();
                    properties.put("mail.store.protocol", "pop3");
                //  properties.put("mail.imap.host", pop3Host);
                //  properties.put("mail.imap.port", 143);
                //  properties.put("mail.smtp.auth.plain.disable", true);
                    properties.put("mail.pop3.starttls.enable", "true");
                    properties.setProperty("ssl.SocketFactory.provider", "ExchangeSSLSocketFactory");
                    properties.setProperty("mail.pop3.socketFactory.class", "ExchangeSSLSocketFactory");
                    Session emailSession = Session.getInstance(properties);
                     emailSession.setDebug(true);
                    // create the POP3 store object and connect with the popserver
                    Store store = emailSession.getStore("pop3s");
                    store.connect(pop3Host, user, password);
    
                    // create the folder object and open it
                    Folder emailFolder = store.getFolder("INBOX");
                    emailFolder.open(Folder.READ_WRITE);
    
    1 回复  |  直到 11 年前
        1
  •  0
  •   Bill Shannon    11 年前

    可能有防火墙阻止您直接连接,要求您通过 proxy server .

    还有,你可能 don't need the special socket factory 。您使用的是“pop3s”协议,但为“pop3”协议设置属性。如果只使用“pop3”协议并设置“mail.pop3.ssl.enable”属性,可能会更简单。如果首先使用SSL连接,则不需要starttls属性。