Search code examples
javaemailexchange-server

read email from an email acount on an exchange server through java mail api


I am trying to access an exchange server to read emails from a specific acount using JAVA mail.

I can access gmail with something like

Properties properties = System.getProperties();
Session session = Session.getDefaultInstance(properties);
store = session.getStore("pop3");
store.connect(host, username, password);

but since I am using exchange I dont have pop3, I only have server name : mysrv ,domain name: MYDOMIAN and a mailbox : [email protected].

So what is the correct way to connect to exchange?


Solution

  • you may try

    Properties properties = System.getProperties();
    Session session = Session.getDefaultInstance(properties);
    store = session.getStore("imap");
    store.connect(host, username, password);