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!