我的公司刚刚将一些邮箱移至O365。不幸的是,这破坏了使用EWS创建的应用程序。尝试调出AutodiscoverUrl()时,遇到错误。
“找不到自动发现服务。”
代码:
service = new ExchangeService(ExchangeVersion.Exchange2010_SP2);
service.UseDefaultCredentials = true;
service.AutodiscoverUrl(mailbox, RedirectionCallback);
private bool RedirectionCallback(string url)
{
return true;
}
我也尝试将URL设置为以下
service.Url = new Uri("https://autodiscover.MYDOMAIN.com/autodiscover/autodiscover.xml");
service.Url = new Uri("https://outlook.office365.com/EWS/Exchange.asmx");
这些都没有解决问题。有人知道从这里去哪里吗?
答案 0 :(得分:0)
URL为https://outlook.office365.com/EWS/Exchange.asmx
public ExchangeService Connect()
{
var lastExchangeVersion = Enum.GetValues(typeof(ExchangeVersion)).Cast<ExchangeVersion>().ToList().Last();
var service = new ExchangeService(lastExchangeVersion)
{
Url = new Uri("https://outlook.office365.com/EWS/Exchange.asmx"),
Credentials = new NetworkCredential(_cloudEmail, _cloudPassword)
};
return service;
}
public SecureString ConvertStringToSecure(string password)
{
if (string.IsNullOrWhiteSpace(password)) return null;
var result = new SecureString();
foreach (char c in password) result.AppendChar(c);
return result;
}