Exchange Web服务问题 - 现场邮箱和异地邮箱
我们系统的各个部分都使用Exchange Web服务发送内部电子邮件并创建日历条目。
从历史上看,我们有一个本地交换服务器托管所有邮箱。但是,我们目前正在迁移到基于云的Exchange服务。
我的问题是,在本地Exchange Server上使用的代码对我们已移动以托管在云上的邮箱不起作用(我们移动了少数用于对其进行测试,然后再进行迁移)。
我认为问题的症结是autodiscoverurl
呼叫 - 此块找到本地托管的邮箱(显然是出于安全原因而匿名):
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls13 | SecurityProtocolType.Tls12 | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls | SecurityProtocolType.Ssl3;
ExchangeService myExchangeService = new ExchangeService(ExchangeVersion.Exchange2007_SP1)
{
TraceEnabled = true,
TraceEnablePrettyPrinting = true,
TraceFlags = TraceFlags.All,
TraceListener = labelTraceListener,
Credentials = new WebCredentials(mySuperUser, mySUPassword),
ImpersonatedUserId = new ImpersonatedUserId(ConnectingIdType.SmtpAddress, "MyEmailName") //The bit before the @
};
myExchangeService.AutodiscoverUrl("MyEmailName@MyDomain", RedirectionCallback);
但是,它看起来像autodiscoverurl
呼叫 call是如果我尝试将模拟目标切换到已迁移到云的邮箱之一,则被未经授权的响应所阻止。考虑到如果我使用与一个远程邮箱直接关联的凭据而不进行模仿,我不太确定问题是什么,它可以正常工作。我已经设法解决了一些可能性 - 但是我无法访问Exchange服务器的配置,因此在我对什么相对结论性的想法之前,我不愿意向网络管理员反弹该问题问题肯定是。
我认为这要么是用于不存在基于云的服务器上的模仿的超级用户帐户的情况,要么是我的Google搜索尚未返回的新设置?
除非我当然在代码本身中做错了什么?
更新:通过将域附加到超级用户(即完整的电子邮件地址),我可以找到所有邮箱 - 它根本缺乏从云托管邮箱中发送任何内容的能力。
收到的例外如下:
There was a problem sending the email - please try again!<br />Microsoft.Exchange.WebServices.Data.ServiceRequestException: The request failed. The remote server returned an error: (401) Unauthorized. ---> System.Net.WebException: The remote server returned an error: (401) Unauthorized.
at System.Net.HttpWebRequest.GetResponse()
at Microsoft.Exchange.WebServices.Data.EwsHttpWebRequest.Microsoft.Exchange.WebServices.Data.IEwsHttpWebRequest.GetResponse() in \\REDMOND\EXCHANGE\BUILD\E15\15.00.0913.015\SOURCES\sources\dev\EwsManagedApi\src\EwsManagedApi\Core\EwsHttpWebRequest.cs:line 113
at Microsoft.Exchange.WebServices.Data.ServiceRequestBase.GetEwsHttpWebResponse(IEwsHttpWebRequest request) in \\REDMOND\EXCHANGE\BUILD\E15\15.00.0913.015\SOURCES\sources\dev\EwsManagedApi\src\EwsManagedApi\Core\Requests\ServiceRequestBase.cs:line 821
--- End of inner exception stack trace ---
at Microsoft.Exchange.WebServices.Data.ServiceRequestBase.GetEwsHttpWebResponse(IEwsHttpWebRequest request) in \\REDMOND\EXCHANGE\BUILD\E15\15.00.0913.015\SOURCES\sources\dev\EwsManagedApi\src\EwsManagedApi\Core\Requests\ServiceRequestBase.cs:line 831
at Microsoft.Exchange.WebServices.Data.ServiceRequestBase.ValidateAndEmitRequest(IEwsHttpWebRequest& request) in \\REDMOND\EXCHANGE\BUILD\E15\15.00.0913.015\SOURCES\sources\dev\EwsManagedApi\src\EwsManagedApi\Core\Requests\ServiceRequestBase.cs:line 724
at Microsoft.Exchange.WebServices.Data.MultiResponseServiceRequest`1.Execute() in \\REDMOND\EXCHANGE\BUILD\E15\15.00.0913.015\SOURCES\sources\dev\EwsManagedApi\src\EwsManagedApi\Core\Requests\MultiResponseServiceRequest.cs:line 157
at Microsoft.Exchange.WebServices.Data.ExchangeService.InternalCreateItems(IEnumerable`1 items, FolderId parentFolderId, Nullable`1 messageDisposition, Nullable`1 sendInvitationsMode, ServiceErrorHandling errorHandling) in \\REDMOND\EXCHANGE\BUILD\E15\15.00.0913.015\SOURCES\sources\dev\EwsManagedApi\src\EwsManagedApi\Core\ExchangeService.cs:line 401
at Microsoft.Exchange.WebServices.Data.Item.InternalCreate(FolderId parentFolderId, Nullable`1 messageDisposition, Nullable`1 sendInvitationsMode) in \\REDMOND\EXCHANGE\BUILD\E15\15.00.0913.015\SOURCES\sources\dev\EwsManagedApi\src\EwsManagedApi\Core\ServiceObjects\Items\Item.cs:line 198
at Microsoft.Exchange.WebServices.Data.EmailMessage.InternalSend(FolderId parentFolderId, MessageDisposition messageDisposition) in \\REDMOND\EXCHANGE\BUILD\E15\15.00.0913.015\SOURCES\sources\dev\EwsManagedApi\src\EwsManagedApi\Core\ServiceObjects\Items\EmailMessage.cs:line 143
at Assets_Controls_EmailControlWrap.btnSend_Click(Object sender, EventArgs e) in N:\Documents\Code\FIS_NewLibrary\Franklin Information System\Assets\Controls\EmailControlWrap.aspx.vb:line 369
Various parts of our system use Exchange Web Services to send internal emails and create calendar entries.
Historically, we have had a local exchange server hosting all mailboxes; however, we are currently in the process of migrating to a cloud-based exchange service.
My issue is that the code that has been working on the local exchange server doesn't work for the mailboxes we've moved to be hosted on the cloud (we moved a handful to test it before committing to the migration).
I think the crux of the issue is the AutodiscoverUrl
call - this block finds the locally hosted mailboxes (obviously anonymised for security reasons):
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls13 | SecurityProtocolType.Tls12 | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls | SecurityProtocolType.Ssl3;
ExchangeService myExchangeService = new ExchangeService(ExchangeVersion.Exchange2007_SP1)
{
TraceEnabled = true,
TraceEnablePrettyPrinting = true,
TraceFlags = TraceFlags.All,
TraceListener = labelTraceListener,
Credentials = new WebCredentials(mySuperUser, mySUPassword),
ImpersonatedUserId = new ImpersonatedUserId(ConnectingIdType.SmtpAddress, "MyEmailName") //The bit before the @
};
myExchangeService.AutodiscoverUrl("MyEmailName@MyDomain", RedirectionCallback);
However, it looks like the AutodiscoverUrl
call is being blocked with an Unauthorised response if I try switching the impersonation target to one of the mailboxes that has been migrated to the cloud. Considering that it works if I use the credentials directly associated with one of the remote mailboxes without doing the impersonation, I'm not too sure what the issue could be. I've managed to pinpoinmt a few possibilities - but I don't have access to the configuration of the exchange servers, so I'm reluctant to bounce the issue to the network administrator before I have a relatively conclusive idea in mind as to what the issue definitely is.
I'm thinking it's either a case of the superuser account being used for the impersonation not being present on the new cloud-based server, or there being a new setting that my googling hasn't returned?
Unless of course I've done something wrong in the code itself?
UPDATE: By appending the domain to the superuser (i.e. the full email address for it), I've got it finding all mailboxes - it simply lacks the ability to send anything from the cloud-hosted mailboxes.
The exception received is as follows:
There was a problem sending the email - please try again!<br />Microsoft.Exchange.WebServices.Data.ServiceRequestException: The request failed. The remote server returned an error: (401) Unauthorized. ---> System.Net.WebException: The remote server returned an error: (401) Unauthorized.
at System.Net.HttpWebRequest.GetResponse()
at Microsoft.Exchange.WebServices.Data.EwsHttpWebRequest.Microsoft.Exchange.WebServices.Data.IEwsHttpWebRequest.GetResponse() in \\REDMOND\EXCHANGE\BUILD\E15\15.00.0913.015\SOURCES\sources\dev\EwsManagedApi\src\EwsManagedApi\Core\EwsHttpWebRequest.cs:line 113
at Microsoft.Exchange.WebServices.Data.ServiceRequestBase.GetEwsHttpWebResponse(IEwsHttpWebRequest request) in \\REDMOND\EXCHANGE\BUILD\E15\15.00.0913.015\SOURCES\sources\dev\EwsManagedApi\src\EwsManagedApi\Core\Requests\ServiceRequestBase.cs:line 821
--- End of inner exception stack trace ---
at Microsoft.Exchange.WebServices.Data.ServiceRequestBase.GetEwsHttpWebResponse(IEwsHttpWebRequest request) in \\REDMOND\EXCHANGE\BUILD\E15\15.00.0913.015\SOURCES\sources\dev\EwsManagedApi\src\EwsManagedApi\Core\Requests\ServiceRequestBase.cs:line 831
at Microsoft.Exchange.WebServices.Data.ServiceRequestBase.ValidateAndEmitRequest(IEwsHttpWebRequest& request) in \\REDMOND\EXCHANGE\BUILD\E15\15.00.0913.015\SOURCES\sources\dev\EwsManagedApi\src\EwsManagedApi\Core\Requests\ServiceRequestBase.cs:line 724
at Microsoft.Exchange.WebServices.Data.MultiResponseServiceRequest`1.Execute() in \\REDMOND\EXCHANGE\BUILD\E15\15.00.0913.015\SOURCES\sources\dev\EwsManagedApi\src\EwsManagedApi\Core\Requests\MultiResponseServiceRequest.cs:line 157
at Microsoft.Exchange.WebServices.Data.ExchangeService.InternalCreateItems(IEnumerable`1 items, FolderId parentFolderId, Nullable`1 messageDisposition, Nullable`1 sendInvitationsMode, ServiceErrorHandling errorHandling) in \\REDMOND\EXCHANGE\BUILD\E15\15.00.0913.015\SOURCES\sources\dev\EwsManagedApi\src\EwsManagedApi\Core\ExchangeService.cs:line 401
at Microsoft.Exchange.WebServices.Data.Item.InternalCreate(FolderId parentFolderId, Nullable`1 messageDisposition, Nullable`1 sendInvitationsMode) in \\REDMOND\EXCHANGE\BUILD\E15\15.00.0913.015\SOURCES\sources\dev\EwsManagedApi\src\EwsManagedApi\Core\ServiceObjects\Items\Item.cs:line 198
at Microsoft.Exchange.WebServices.Data.EmailMessage.InternalSend(FolderId parentFolderId, MessageDisposition messageDisposition) in \\REDMOND\EXCHANGE\BUILD\E15\15.00.0913.015\SOURCES\sources\dev\EwsManagedApi\src\EwsManagedApi\Core\ServiceObjects\Items\EmailMessage.cs:line 143
at Assets_Controls_EmailControlWrap.btnSend_Click(Object sender, EventArgs e) in N:\Documents\Code\FIS_NewLibrary\Franklin Information System\Assets\Controls\EmailControlWrap.aspx.vb:line 369
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
使用此工具: https://aka.ms/pillarexobasicacicauth 我们找到了这个问题 - 而UI则说明了UI这个基本问题auth被打开了,不在后端。将其打开正确解决了问题。
Using this tool: https://aka.ms/PillarEXOBasicAuth we found the issue - while the UI said that Basic Auth was turned on, it wasn't in the back-end; turning it on properly resolved the issue.