[英]The request failed. The remote server returned an error: (401) Unauthorized error while connecting to Office365
I'm getting above error message while connecting to Office365 . 连接到Office365时出现上述错误消息。
ExchangeService serviceInstance = new ExchangeService(ExchangeVersion.Exchange2013_SP1);
serviceInstance.Credentials = new WebCredentials("sample@microsoft.com", "Password", "REDMOND");
serviceInstance.Url = new Uri("https://outlook.office365.com/EWS/Exchange.asmx");
foreach (EmailMessage email in serviceInstance.FindItems(WellKnownFolderName.Inbox, new ItemView(100)))
{
}
Both Username and Pwd are correct but still getting issue. 用户名和密码都是正确的,但仍然存在问题。
Kindly suggest. 请提示。
You shouldn't be specifying the domain in 您不应该在指定域
serviceInstance.Credentials = new WebCredentials("sample@microsoft.com", "Password", "REDMOND"); serviceInstance.Credentials =新的WebCredentials(“ sample@microsoft.com”,“ Password”,“ REDMOND”);
just use the user account upn only (and that maybe different from the Email Address) 仅使用用户帐户upn(可能与电子邮件地址不同)
serviceInstance.Credentials = new NetworkCredential("sample@microsoft.com", "Password"); serviceInstance.Credentials =新的NetworkCredential(“ sample@microsoft.com”,“ Password”);
or try the down-level format 或尝试下层格式
serviceInstance.Credentials = new NetworkCredential("domain\\user\u0026quot;, "Password"); serviceInstance.Credentials =新的NetworkCredential(“ domain \\ user”,“ Password”);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.