当我从本地主机尝试时,我能够成功地使用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);