Search code examples
jakarta-mailexchange-server

How to use Javamail for accessing additional mailboxes (IMAP, Exchange 2010)


I want to access a shared mailbox (NOT FOLDER) via Javamail API (1.4.5) using IMAP(s) with plain logon. The mailserver is a Exchange Server 2010.

User: user1 ([email protected]) pwd: xxxx

shared mailbox: [email protected]

I´ve managed to get access to the user1 - mailbox:

    Session session = Session.getInstance(properties, new ExchangeAuthenticator(username, password));
        session.setDebug(true);

        Store store = session.getStore("imaps");

        store.connect(imapHost, username, password);

properties:

mail.imaps.socketFactory.port = 993

mail.imaps.starttls.enable = true

mail.imaps.socketFactory.class = javax.net.ssl.SSLSocketFactory

mail.imaps.socketFactory.fallback = false

username = [email protected]

password = xxxx

--> this works just fine! But now i want to access the additional mailbox by changing the login-String:

[email protected]/shared_MB

--> unfortunately I´m getting an "NO AUTHENTICATE" message:

   DEBUG IMAP: AUTHENTICATE PLAIN command result: A1 NO AUTHENTICATE failed.

I was able to get access with Thunderbird, so I think there is something missing in my code...


Solution

  • I am doing the following and it is working fine for me

    properties = System.getProperties();
    properties.setProperty("mail.imaps.auth.plain.disable", "true");
    properties.setProperty("mail.imaps.auth.ntlm.disable", "true");
    Session session = Session.getInstance(properties, null);
    store = session.getStore("imaps");
    store.connect("HOST", PORT, "DOMAIN\\USER\\SHAREDACCOUNT","pwd");
    

    Here DOMAIN\\USER\\SHAREDACCOUNT would be like this
    suppose email account is [email protected] then
    abc\\tarun\\shared_MB

    You have to also enter the password of [email protected] account.