1

我有一个使用 MS Exchange Server 2010 SP2 的 Web 服务发送电子邮件的应用程序 (C#)。它以前工作正常。但是,就在两周前,我遇到了问题。有时代码可以发送电子邮件,但有时不能。我收到如下错误消息(最后显示完整的错误消息)。

The request failed. Unable to connect to the remote server

我的代码如下。

string ewsUrl = "https://xxxx.xxxx.com/ews/Exchange.asmx";
string userName = "xxxx";
string password = "xxxx";
string to = "xxxx@xxxx.com";
string cc = "xxxx@xxxx.com";

ExchangeService service = new ExchangeService();
service.Url = new Uri(ewsUrl);
service.UseDefaultCredentials = true;
service.Credentials = new WebCredentials(userName, password);

EmailMessage message = new EmailMessage(service);
message.Subject = subject;
message.Body = bodyHtml;
message.ToRecipients.Add(to);
message.CcRecipients.Add(cc);

message.SendAndSaveCopy();

我不知道出了什么问题。我相信该 URL 是正确的,它有时会起作用,但有时会不起作用。我在互联网上进行了搜索,但没有找到任何解决方案。这与服务器配置有关吗?我已经和我的 IT 人员谈过了,但他似乎对 Web 服务一无所知。请帮我。完整的错误消息如下。

The request failed. Unable to connect to the remote server
    at Microsoft.Exchange.WebServices.Data.ServiceRequestBase.ValidateAndEmitRequest(HttpWebRequest& request)
    at Microsoft.Exchange.WebServices.Data.SimpleServiceRequestBase.InternalExecute()
    at Microsoft.Exchange.WebServices.Data.MultiResponseServiceRequest`1.Execute()
    at Microsoft.Exchange.WebServices.Data.ExchangeService.InternalCreateItems(IEnumerable`1 items, FolderId parentFolderId, Nullable`1 messageDisposition, Nullable`1 sendInvitationsMode, ServiceErrorHandling errorHandling)
    at Microsoft.Exchange.WebServices.Data.ExchangeService.CreateItem(Item item, FolderId parentFolderId, Nullable`1 messageDisposition, Nullable`1 sendInvitationsMode)
    at Microsoft.Exchange.WebServices.Data.Item.InternalCreate(FolderId parentFolderId, Nullable`1 messageDisposition, Nullable`1 sendInvitationsMode)
    at Microsoft.Exchange.WebServices.Data.EmailMessage.InternalSend(FolderId parentFolderId, MessageDisposition messageDisposition)
    at Microsoft.Exchange.WebServices.Data.EmailMessage.Send()
4

1 回答 1

0
ServicePointManager.ServerCertificateValidationCallback = 
    delegate(object sender1,
             System.Security.Cryptography.X509Certificates.X509Certificate certificate,
             System.Security.Cryptography.X509Certificates.X509Chain chain,
             System.Net.Security.SslPolicyErrors sslPolicyErrors) 
    { return true; };

message.CcRecipients.Add(cc); 我认为您需要在和之间添加上述代码message.SendAndSaveCopy();

于 2012-12-21T20:38:41.653 回答