dcsimg
How do I configure JavaMail to work through a proxy server?
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Ketan_Chachad
Posted On:   Monday, March 15, 2004 12:30 AM

Hi, I have written a Java program that uses JavaMail API but this program works only when there is a direct connection between the machine where the program is executed and the Internet. I now want to make the program work when it behind a fire-wall. Can anyone tell me what additional code I will have to write for the same? I added proxy host and port to the the system properties as System.setProperty("proxyHost", proxyIPAddress); System.setProperty("proxyPort", proxyPort); Still the code does not work. Can anyone help me out? Its very urgent!!!    More>>


Hi,



I have written a Java program that uses JavaMail API but this program works only when there is a direct connection between the machine where the program is executed and the Internet.



I now want to make the program work when it behind a fire-wall. Can anyone tell me what additional code I will have to write for the same? I added proxy host and port to the the system properties as



System.setProperty("proxyHost", proxyIPAddress);

System.setProperty("proxyPort", proxyPort);


Still the code does not work. Can anyone help me out? Its very urgent!!!

   <<Less

Re: How do I configure JavaMail to work through a proxy server?

Posted By:   Adam_Flint  
Posted On:   Wednesday, March 31, 2004 03:50 AM

We use the code below to get through a proxy when trying to make an Http connection from Java. Not the same as sending emails, I know, but it might help. The main thing I found is that the user id and password have to be base64 encoded.


// Set up our authentication
String auth = "username:password";
String smsAuthentication = "Basic " + new sun.misc.BASE64Encoder().encode(auth.getBytes());
System.setProperty("http.proxySet","true");
System.setProperty("http.proxyHost", getProxyLocation() );
System.setProperty("http.proxyPort", getProxyPort() );

HttpURLConnection conn = (HttpURLConnection) url.openConnection();

conn.setRequestProperty("Proxy-Authorization", smsAuthentication);

int response = conn.getResponseCode();
conn.disconnect();
About | Sitemap | Contact