Skip to Main Content

Java EE (Java Enterprise Edition) General Discussion

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

How to set proxy to javamail?

843830Mar 31 2005
Hi friends:

I want to receieve email using javamail. I use code:
Properties prop=new Properties(); 
	  prop.put("mail.pop3.host",host); 
	  prop.put("mail.smtp.auth","true");//
	  Session session=Session.getDefaultInstance(prop); 
	  session.setDebug(true);
	  
	  Store store=session.getStore("pop3"); 
	  store.connect(host,name,password); 
	   
	  Folder inbox=store.getDefaultFolder().getFolder("INBOX"); 
	  inbox.open(Folder.READ_ONLY); 
	   
	  Message[] msg=inbox.getMessages(); 
	   
	  FetchProfile profile=new FetchProfile(); 
	  profile.add(FetchProfile.Item.ENVELOPE); 
	  inbox.fetch(msg,profile);
When I run it, I get exception:
DEBUG: getProvider() returning javax.mail.Provider[STORE,pop3,com.sun.mail.pop3.POP3Store,Sun Microsystems, Inc]
POP3: connecting to host "pop.163.com", port 110
javax.mail.MessagingException: Connect failed;
  nested exception is: 
	java.net.ConnectException: Connection refused: connect
	at com.sun.mail.pop3.POP3Store.protocolConnect(POP3Store.java:106)
	at javax.mail.Service.connect(Service.java:234)
	at javax.mail.Service.connect(Service.java:135)
	at com.developcentry.mail.MailTest.getMail(MailTest.java:44)
	at com.developcentry.mail.MailTest.getMsgList(MailTest.java:65)
	at com.developcentry.mail.MailTest.main(MailTest.java:60)
Exception in thread "main" 
It maybe I am in the intranat,so It is limited by proxy. Is there any method to set proxy to javamail? For example:

session.set("proxy","address");
If it has ,how to do it? THKS!
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Apr 28 2005
Added on Mar 31 2005
0 comments
338 views