how to read inbox using javamail from microsoft exchange server
819306Jan 27 2011 — edited Feb 2 2011Hi,
I want to read mails from microsoft exchange server using javamail.I use the following code
String username = "ggg@fff.com";
String password = "sdasdas";
Properties props = System.getProperties();
Authenticator auth = new Authenticator()
{
public PasswordAuthentication getPasswordAuthentication()
{
return new PasswordAuthentication(username , password );
}
};
Session session = Session.getDefaultInstance(props, auth);
System.out.println(session);
Store store = session.getStore("imaps");
System.out.println(store);
store.connect(host, username, password);
// Get folder
Folder folder = store.getFolder("INBOX");
folder.open(Folder.READ_ONLY);
// Get directory
Message message[] = folder.getMessages();
for (int i=0, n=message.length; i<n; i++) {
System.out.println(i + ": " + message.getFrom()[0]
+ "\t" + message[i].getSubject());
}
// Close connection
folder.close(false);
store.close();
But I got error
javax.mail.MessagingException: Connection timed out: connect;
nested exception is:
java.net.ConnectException: Connection timed out: connect
at com.sun.mail.imap.IMAPStore.protocolConnect(IMAPStore.java:571)
at javax.mail.Service.connect(Service.java:288)
at javax.mail.Service.connect(Service.java:169)
at Shipmate.MyJavaMail.reaadMail(MyJavaMail.java:580)
at Shipmate.MyJavaMail.main(MyJavaMail.java:46)
I can access mails through Microsoft accesss office outlook in the configuration of that 1.it use connect to mymailbox using HTTP
2.In connection setting a Url is provided to connect to my proxyserver exchange.like https//sadsadsa.asdasds@asdsf.com
3.mutually authenticate the session with ssl and provide the principal name for proxy server
4.And also basic authentication is used for connecting my proxy server for exchange.
The above are the settings done in my microsoft outlook 2003 so that I can read the mail in that.
But I would like to read inbox using Javamail.How can I do that?
Thanks in Advance