Exchange Web 服务连接失败
Exchange web Services failed to connect
我的office 365有在线兑换服务,
我想用不同的方法发送电子邮件到其他人的邮箱
然后我找到了 Exchange Web 服务,所以我尝试做基本的例子:
class Program
{
static void Main(string[] args)
{
//note that there no option for exchange server 2016 (my exchange online use exchange server 2016), so i use the default option
ExchangeService service = new ExchangeService(ExchangeVersion.Exchange2007_SP1);
service.Credentials = new WebCredentials("user@domain.com", "myPassword");
service.UseDefaultCredentials = false;
//for log purpose
service.TraceEnabled = true;
service.TraceFlags = TraceFlags.All;
service.AutodiscoverUrl("user@domain.com", RedirectionUrlValidationCallback);
EmailMessage email = new EmailMessage(service);
email.ToRecipients.Add("user2@domain.com");
email.Subject = "HelloWorld";
email.Body = new MessageBody("This is the first email I've sent by using the EWS Managed API.");
email.Send();
}
private static bool RedirectionUrlValidationCallback(string redirectionUrl)
{
// The default for the validation callback is to reject the URL.
bool result = false;
Uri redirectionUri = new Uri(redirectionUrl);
// Validate the contents of the redirection URL. In this simple validation
// callback, the redirection URL is considered valid if it is using HTTPS
// to encrypt the authentication credentials.
if (redirectionUri.Scheme == "https")
{
result = true;
}
return result;
}
}
并且在 AutodiscoverUrl 中有异常,像这样:
Microsoft.Exchange.WebServices.Data.ServiceXmlDeserializationException: 'The
expected XML node type was XmlDeclaration, but the actual type is Element.'
找了一会,说exchange找不到我的域名,我的exchange online设置没问题,我可以发邮件,通过outlook web access添加预约到我邮箱里的其他人
我已经将我的名称服务器更改为
ns1.bdm.microsoftonline.com
ns2.bdm.microsoftonline.com
但还是没有解决我的问题..
有没有我遗漏的设置?
谢谢..
而不是使用
service.AutodiscoverUrl("user@domain.com", RedirectionUrlValidationCallback);
尝试
service.Url = new Uri("https://outlook.office365.com/EWS/Exchange.asmx");
我建议你设置
ExchangeService service = new ExchangeService(ExchangeVersion.Exchange2007_SP1);
Office365 的最高枚举而不是最低枚举,除非您尝试支持 Exchange 2007。
我的office 365有在线兑换服务,
我想用不同的方法发送电子邮件到其他人的邮箱
然后我找到了 Exchange Web 服务,所以我尝试做基本的例子:
class Program
{
static void Main(string[] args)
{
//note that there no option for exchange server 2016 (my exchange online use exchange server 2016), so i use the default option
ExchangeService service = new ExchangeService(ExchangeVersion.Exchange2007_SP1);
service.Credentials = new WebCredentials("user@domain.com", "myPassword");
service.UseDefaultCredentials = false;
//for log purpose
service.TraceEnabled = true;
service.TraceFlags = TraceFlags.All;
service.AutodiscoverUrl("user@domain.com", RedirectionUrlValidationCallback);
EmailMessage email = new EmailMessage(service);
email.ToRecipients.Add("user2@domain.com");
email.Subject = "HelloWorld";
email.Body = new MessageBody("This is the first email I've sent by using the EWS Managed API.");
email.Send();
}
private static bool RedirectionUrlValidationCallback(string redirectionUrl)
{
// The default for the validation callback is to reject the URL.
bool result = false;
Uri redirectionUri = new Uri(redirectionUrl);
// Validate the contents of the redirection URL. In this simple validation
// callback, the redirection URL is considered valid if it is using HTTPS
// to encrypt the authentication credentials.
if (redirectionUri.Scheme == "https")
{
result = true;
}
return result;
}
}
并且在 AutodiscoverUrl 中有异常,像这样:
Microsoft.Exchange.WebServices.Data.ServiceXmlDeserializationException: 'The
expected XML node type was XmlDeclaration, but the actual type is Element.'
找了一会,说exchange找不到我的域名,我的exchange online设置没问题,我可以发邮件,通过outlook web access添加预约到我邮箱里的其他人
我已经将我的名称服务器更改为
ns1.bdm.microsoftonline.com
ns2.bdm.microsoftonline.com
但还是没有解决我的问题..
有没有我遗漏的设置?
谢谢..
而不是使用
service.AutodiscoverUrl("user@domain.com", RedirectionUrlValidationCallback);
尝试
service.Url = new Uri("https://outlook.office365.com/EWS/Exchange.asmx");
我建议你设置
ExchangeService service = new ExchangeService(ExchangeVersion.Exchange2007_SP1);
Office365 的最高枚举而不是最低枚举,除非您尝试支持 Exchange 2007。