javamail access to a shared mailbox

后端 未结 3 926
灰色年华
灰色年华 2021-01-13 07:01

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

3条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2021-01-13 07:35

    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, "user@xyz.com\\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, "user@xyz.com\\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, "user@xyz.com", "user_password");
    

提交回复
热议问题