Skip to content
Advertisement

How to let javamail support http proxy

I found that javamail only support socks. Is there any solution I can use to support http proxy?

public class MailConnectionTest {
 public static void main(String args[]) throws MessagingException {
   Properties props = MailConnectionTest.getProperties();
   Session session = Session.getDefaultInstance(props, null);
   String protocol = "pop3";
   String host = "pop.163.com";
   String username = "email username";
   String password = "1Qaz2wsx3edc&";
   Store store = session.getStore(protocol);
   store.connect(host, username, password);
   System.out.println("Success");
}
private static Properties getProperties() {
 Properties props = System.getProperties();
 props.put("mail.debug", "false");
 // Proxy
 props.put("proxySet", "true");
 props.put("http.proxyHost", "proxyAdderss");
 props.put("http.proxyPort", "8080");
 return props;
}
}

Advertisement

Answer

See the JavaMail FAQ:

… Without such a SOCKS server, if you want to use JavaMail to access mail servers outside the firewall indirectly, you might be able to use a program such as Corkscrew or connect to tunnel TCP connections through an HTTP proxy server. JavaMail does not support direct access through an HTTP proxy web server.

5 People found this is helpful
Advertisement