从localhost尝试时,我成功地能够使用javamail读取和删除邮件但是当我在服务器上部署java代码并尝试调用该服务时,它会卡在store.connect(pop3Host,user,password); < / p>
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);
答案 0 :(得分:0)
可能存在阻止您直接连接的防火墙,要求您通过proxy server进行连接。
另外,你可能don't need the special socket factory。而你正在使用“pop3s”协议,但设置“pop3”协议的属性。如果您只使用“pop3”协议并设置“mail.pop3.ssl.enable”属性,则可能更简单。如果您要使用SSL连接,则不需要starttls属性。