【发布时间】:2019-02-21 12:45:16
【问题描述】:
遇到错误
Microsoft.Exchange.WebServices.dll 中出现“Microsoft.Exchange.WebServices.Data.AutodiscoverLocalException”类型的未处理异常
ExchangeService oews = new ExchangeService(ExchangeVersion.Exchange2013_SP1)
{
Credentials = new WebCredentials("mohanb@cubicsp.onmicrosoft.com","******") //state your Exchange username,Exchange Password and Exchange Domain
};
oews.AutodiscoverUrl("mohanb@cubicsp.onmicrosoft.com"); //User Mailbox whose inbox is to be accessed.
FindFoldersResults foundFolderResults = oews.FindFolders(WellKnownFolderName.Inbox, new FolderView(int.MaxValue));
MEWS.Folder exchangeExchangeAPIArchivedFolder = foundFolderResults.Folders.ToList().Find(
f => f.DisplayName.Equals("SentItem", StringComparison.CurrentCultureIgnoreCase));
我在此处使用 https://outlook.office365.com/EWS/Exchange.asmx 更改了代码 现在我收到此错误
Microsoft.Exchange.WebServices.dll 中出现“Microsoft.Exchange.WebServices.Data.ServiceRequestException”类型的未处理异常
附加信息:请求失败。远程服务器返回错误:(401) Unauthorized.
ExchangeService _service = new ExchangeService();
_service.Url = new Uri("https://outlook.office365.com/EWS/Exchange.asmx");
foreach (EmailMessage email in _service.FindItems(WellKnownFolderName.Inbox, new ItemView(10))) {
email.Load(new PropertySet(BasePropertySet.FirstClassProperties, ItemSchema.TextBody));
string recipients = "";
foreach (EmailAddress emailAddress in email.CcRecipients)
{
recipients += ";" + emailAddress.Address.ToString();
}
string internetMessageId = email.InternetMessageId;
string fromAddress = email.From.Address;
string recipient = recipients;
string subject = email.Subject;
}
提前致谢
【问题讨论】:
-
你确定“mohanb@cubicsp.sharepoint.com”是邮箱地址吗?你试过“mohanb@cubicsp.onmicrosoft.com”吗?
-
感谢 Dmitry,我错误地粘贴了电子邮件地址,但更改后仍然出现同样的错误。