d33j
d33j

Reputation: 434

javamail access to a shared mailbox

I'm trying to write an java application that will access a additional, shared mailbox to read emails and perform other activities. I have no problem reading my own INBOX (or its folders & contents) but am having great difficulty finding information on how to access (and ultimately parse/read) a shared mailbox.

Upvotes: 7

Views: 10878

Answers (3)

TomWolk
TomWolk

Reputation: 987

With the help from the other answers, I figured out following solution, that works for com.sun.mail:javax.mail:1.6.2

Properties props = new Properties();
props.setProperty("mail.imaps.auth.mechanisms", "LOGIN");
Session session = Session.getInstance(props);
Store store = session.getStore("imaps");
store.connect("outlook.office365.com", 993, "[email protected]\\shared_account_alias", "user_password");

With javax.mail:mail:1.4.7 following code works:

Properties props = new Properties();
props.setProperty("mail.imaps.auth.plain.disable", "true");
Session session = Session.getInstance(props);
Store store = session.getStore("imaps");
store.connect("outlook.office365.com", 993, "[email protected]\\shared_account_alias", "user_password");

shared_account_alias is NOT the email address.

Eventually I have found a more standard way of accessing the shared mailbox:

Properties props = new Properties();
props.setProperty("mail.imaps.sasl.enable", "true");
props.setProperty("mail.imaps.sasl.authorizationid", "shared_account_alias");
Session session = Session.getInstance(props);
Store store = session.getStore("imaps");
store.connect("outlook.office365.com", 993, "[email protected]", "user_password");

Upvotes: 6

Anuja
Anuja

Reputation: 419

The solution given by Tarun works. But an important note use the alias of the shared account and not the actual email address of shared account. So the actual format is: store.connect(DOMAIN, "[email protected]\SHARED_ACCOUNT_ALIAS","USER_PASSWORD");

Upvotes: 3

Tarun Nagpal
Tarun Nagpal

Reputation: 964

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 also have to enter the password of [email protected] account.

Upvotes: 5

Related Questions