2016-12-06 80 views
0

當我試圖訪問像無法訪問Outlook的共享郵箱與Java IMAPS

store.connect("imaps store address", 993, "[email protected]","PASSWORD"); 

我的郵箱,我可以能夠訪問郵箱。但是,當我試圖像以下:

store.connect("imaps store address", 993, "[email protected]/sharedmailbox_name","PASSWORD"); 

store.connect("imaps store address", 993, "[email protected]/[email protected]","PASSWORD"); 

我收到此錯誤:

Connecting to the IMAP server...javax.mail.AuthenticationFailedException: AUTHENTICATE failed. at com.sun.mail.imap.IMAPStore.protocolConnect(IMAPStore.java:725) at javax.mail.Service.connect(Service.java:366) at pkg.finale.test.CheckOutlook.initiate(CheckOutlook.java:38) at 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,"[email protected]/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(); 
     } 
    } 
+0

這是否與Outlook有關? –

+0

我在你的代碼塊之前移動了你的問題陳述。用一些上下文消化代碼通常更容易。 – Chris

+0

是的,我正在嘗試連接到Microsoft Exchange Outlook。我仍然有問題。 – Bramha

回答

0

我終於破解但它使用EWS Api。

ExchangeService service = new ExchangeService(ExchangeVersion.Exchange2010_SP1); 
String username = "[email protected]"; 
ExchangeCredentials credentials = new WebCredentials(username,Password); 
service.setCredentials(credentials); 
service.autodiscoverUrl(username); 
ItemView view = new ItemView (10); 
Mailbox mb = new Mailbox(); 
mb.setAddress("[email protected]"); 
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()); 
} 
+0

@Brama:你能幫我從公共文件夾中獲取文件夾嗎?當我嘗試在您的代碼中替換行時,出現「有沒有公用文件夾服務器可用」的錯誤FolderId folderId = new FolderId(WellKnownFolderName.Inbox,MB);與FolderId folderId =新的FolderId(WellKnownFolderName.PublicFoldersRoot,MB); – yatinbc