无法使用Java IMAPS访问Outlook的共享邮箱

时间:2016-12-06 22:04:35

标签: java javamail exchange-server

当我尝试访问我的邮箱时

store.connect("imaps store address", 993, "someone@domain.com","PASSWORD");

我可以访问邮箱。但是,当我尝试跟随时:

store.connect("imaps store address", 993, "someone@domain.com/sharedmailbox_name","PASSWORD");

store.connect("imaps store address", 993, "someone@domain.com/sharedmailbox_name@domain.com","PASSWORD");

我收到此错误:

  

连接到IMAP服务器... javax.mail.AuthenticationFailedException:AUTHENTICATE失败。       在com.sun.mail.imap.IMAPStore.protocolConnect(IMAPStore.java:725)       在javax.mail.Service.connect(Service.java:366)       at pkg.finale.test.CheckOutlook.initiate(CheckOutlook.java:38)       在pkg.finale.test.CheckOutlook.main(CheckOutlook.java:17)

以下是代码:

import java.util.Properties;

public class CheckOutlook {

    public static void main(String[] args) {
        initiate();
    }

public static void initiate(){         
    try {
        Properties properties = System.getProperties();
        properties.setProperty("mail.imaps.auth.ntlm.disable", "false");
        properties.setProperty("mail.protocol.ssl.trust", "true");
        properties.put("mail.imap.starttls.enable", "true");
        Session session = Session.getInstance(properties, null);

        System.out.print("Connecting to the IMAP server...");

        String storeName = "imaps";
        Store store = session.getStore(storeName);
        store.connect("imaps store address", 993,"someone@domain.com/SharedMailboxName","Password");

        System.out.println("Connected To server: Done!");
        Folder[] f = store.getDefaultFolder().list();
        for(Folder fd:f)
               System.out.println(">> "+fd.getName());
        System.out.println();
           Folder inbox = store.getFolder("inbox");
           inbox.open(Folder.READ_WRITE);
           Message messages[] = inbox.search(new FlagTerm(new Flags(Flag.SEEN), false));
       }
       catch(Exception E){
           E.printStackTrace();
       }
   }

1 个答案:

答案 0 :(得分:0)

最后我使用EWS Api破解了它。

ExchangeService service = new ExchangeService(ExchangeVersion.Exchange2010_SP1);
String username = "username@domain.com";
ExchangeCredentials credentials = new WebCredentials(username,Password);
service.setCredentials(credentials);
service.autodiscoverUrl(username);
ItemView view = new ItemView (10);
Mailbox mb = new Mailbox();
mb.setAddress("sharedmailboxname@domain.com");
FolderId folderId = new FolderId(WellKnownFolderName.Inbox, mb);
FindItemsResults<Item> findResults = service.findItems( folderId, view);
for (Item item1 : findResults.getItems()) {
  item1.load();
  System.out.println(item1.getSubject());
}