store.connect()不适用于代理上的gmail imap

时间:2014-07-03 09:52:42

标签: java smtp javamail imap network-protocols

store.connect()不适用于我的代码中的gmail imap代理:

Properties props = new Properties();
props.setProperty("mail.store.protocol", "imaps");
Session session = Session.getInstance(props, null);
Store store = session.getStore("imaps");
store.connect("imap.gmail.com", email, pass);
Folder inbox = store.getFolder("INBOX");
inbox.open(Folder.READ_ONLY);

获得以下错误:

  

javax.mail.MessagingException:连接被拒绝:连接;嵌套   异常是:java.net.ConnectException:连接被拒绝:连接

已经尝试过:

  1. http://developers.viafirma.com/en/proxy-connection-problems-connection-refused
  2. JavaMail SMTP-host error
  3. http://javarevisited.blogspot.in/2013/02/java-net-ConnectException-Connection-refused.html

1 个答案:

答案 0 :(得分:0)

当我使用下面的代码和端口代码时,我的问题就解决了:

Properties props = new Properties();
props.setProperty("http.proxySet", "true");
props.setProperty("http.proxyHost", proxyHost);
props.setProperty("http.proxyPort", proxyPort);
props.setProperty("mail.imap.port", "993");
props.setProperty("mail.store.protocol", "imaps");
Session session = Session.getInstance(props, null);
Store store = session.getStore("imaps");
store.connect("imap.gmail.com", email, pass);
Folder inbox = store.getFolder("INBOX");
inbox.open(Folder.READ_ONLY);