簡體   English   中英

無法以編程方式使用MS Exchange Server 2010 SP2的Web服務發送電子郵件

[英]Can not programmatically send email using web service of MS Exchange Server 2010 SP2

我有一個應用程序(C#),該應用程序使用MS Exchange Server 2010 SP2的Web服務發送電子郵件。 以前工作正常。 但是,就在2周前,我遇到了問題。 該代碼有時可以發送電子郵件,但有時不能。 我收到以下錯誤消息(最后顯示完整的錯誤消息)。

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();

我不知道出了什么問題。 我認為該網址是正確的,並且可以在某個時間而不是其他時間正常工作。 我在互聯網上進行搜索,但沒有找到任何解決方案。 這與服務器配置有關嗎? 我已經與我的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()
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.CcRecipients.Add(cc); message.SendAndSaveCopy();

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM