如果您看到注释行代码store.connect ....我试图通过用户邮箱[迁移到云]访问共享邮箱,该邮箱在此共享邮箱上具有委派访问权限。在运行这个我得到
javax.mail.AuthenticationFailedException: LOGIN failed.
at com.sun.mail.imap.IMAPStore.protocolConnect(IMAPStore.java:715)
at javax.mail.Service.connect(Service.java:364)
at com.adecco.smpt.TestSSL.main(TestSSL.java:26)
如果我尝试访问用户邮箱而不是共享邮箱一切正常。是否有不同的语法来访问JAVA中的SHARED MAILBOX?提前致谢。
import java.util.Properties;
import javax.mail.*;
public class TestSSL {
public static void main(String[] args) {
Properties props = System.getProperties();
props.put("mail.imaps.auth.plain.disable", "true");
props.put("mail.smtp.ssl.enable", "true");
try {
Session session = Session.getInstance(props, null);
session.setDebug(true);
Store store = session.getStore("imaps");
store.connect("outlook.office365.com", 993, "office 365 username/alias name of shared MAILBOX", "PASSWORD");
System.out.println(store);
Folder inbox = store.getFolder("Inbox");
inbox.open(Folder.READ_ONLY);
Message messages[] = inbox.getMessages();
for (Message message : messages) {
System.out.println(message);
}
} catch (Exception e) {
e.printStackTrace();
System.exit(2);
}
}
}