Andrew
Andrew

Reputation: 17

How do I set Internet Proxy on Apache Commons Mail Api?

I would like to send email using a custom proxy on apache commons email api because I'm connected to the internet through a proxy server.

I've tried using the common ways of setting proxies in java but it doesn't seem to work. e.g

System.getProperties().put("http.proxySet", "true" ); 
System.getProperties().put("http.proxyHost", "127.0.0.1");
System.getProperties().put("http.proxyPort", "6056");

And

System.getProperties().put("http.proxySet", "true" );     
System.setProperty("http.proxyHost", "127.0.0.1");     
System.setProperty("http.proxyPort", "6056");`

Thanks.

Upvotes: 1

Views: 1407

Answers (1)

T. Neidhart
T. Neidhart

Reputation: 6200

Something like this should work:

  Email mail = ....

mail.getSession().getProperties().setProperty("mail.smtp.socks.host", "my.socks.host");
  ...

  mail.send();

Upvotes: 1

Related Questions