0
在發佈之前,我已經經歷了類似的帖子,但找不到解決方案。我正在嘗試使用EWS API閱讀我的Outlook收件箱,但我一直收到401訪問被拒絕的錯誤。請幫幫我。通過EWS連接到Outlook收件箱時出錯
我已經設置了用戶名,密碼和域名按照API的需要,但不知道爲什麼會出現401
public final class ExchangeServerConnection {
private static String exchangemailurl;
private static String userName;
//private static String password;
private ExchangeServerConnection() {
}
public static ExchangeService connectionEWS(String string) {
// TODO Auto-generated method stub
{
ExchangeService service = null;
try {
service = new ExchangeService(ExchangeVersion.Exchange2010_SP2);
ExchangeCredentials credentials = new WebCredentials("[email protected]", "Uddsa#2k16", null);
service.setCredentials(credentials);
service.setUrl(new URI("https://email-domain.com/ews/Exchange.asmx"));
} catch (URISyntaxException e) {
}
return service;
}
}
}
主要類:
public class EmailUtil {
public static void main (String args[]) throws Exception{
ExchangeService service = ExchangeServerConnection.connectionEWS("Uaua#2k16");
System.err.println("Connections has been set up");
FolderView view1 = new FolderView(EWSConstants.TEN.getNumber());
System.err.println("1");
// ExtendedPropertyDefinition isHiddenProp = new ExtendedPropertyDefinition(EWSConstants.PRODDEF.getNumber(),
// MapiPropertyType.Boolean);
System.err.println("2");
//PropertySet pr1 = new PropertySet(BasePropertySet.IdOnly, FolderSchema.DisplayName, isHiddenProp);
// view1.setPropertySet(pr1);
System.err.println("3");
view1.setTraversal(FolderTraversal.Deep);
System.err.println("4");
SearchFilter searchFilter1 = new SearchFilter.IsEqualTo(FolderSchema.DisplayName, EWSConstants.INBOX.getValue());
System.err.println("5");
searchFilter1 = new SearchFilter.SearchFilterCollection(LogicalOperator.Or, searchFilter1);
System.err.println("6");
FindFoldersResults findFolderResults = service.findFolders(WellKnownFolderName.MsgFolderRoot, searchFilter1, view1);
System.err.println("7");
Folder folder = findFolderResults.getFolders().get(0);
System.err.println("8");
folder.load();
System.err.println(folder.getTotalCount());
int messageCount = folder.getTotalCount();
System.err.println("message count is "+messageCount);
}
}
'ExchangeCredentials憑證= \t新WebCredentials( 「Murali.S」, 「合格」,「host.comp .com「);' 但它仍然拋出相同的錯誤 – Jackson2489