web
You’re offline. This is a read only version of the page.
close
Skip to main content
Community site session details

Community site session details

Session Id :
Microsoft Dynamics 365 | Integration, Dataverse...
Answered

Email Server Error Code: Http server returned Unauthorized exception (Exchnage & D365) on prem

(3) ShareShare
ReportReport
Posted on by 93
Hi All, I'm managing a CRM on-prem v9.1 and there is a production issue with the email configuration on browsing and by telnet it's connection is fine, but from the CRM email profile and mailbox getting unauthorized. BTW for the outgoing sending test getting the unauthorized and receiving tests have been successful. We have already opened a ticket with the support team, but still do not get anything, and would like to raise that we have checked the impersonation settings. It works fine from a connection tool and gets unauthorized while sending any Post request to *exchange domain*/EWS/Exchange.asmx
 
Updates !
I've created a console app and I've tried to execute from each server and figured that from front servers it's sending fine while back servers are getting unauthorized I believe that I'm close to the solution 
Categories:
I have the same question (0)
  • Verified answer
    Abanoub_D365 Profile Picture
    93 on at
    Email Server Error Code: Http server returned Unauthorized exception (Exchnage & D365) on prem
    Resolved since not calling a load balancer mail URL and working with an Exchange server-specific URL, I think it's related to the network and Exchange team
  • Abanoub_D365 Profile Picture
    93 on at
    Email Server Error Code: Http server returned Unauthorized exception (Exchnage & D365) on prem
    Appreciated ,
     For your detailed steps and aspects of the root causes, I've updated the issue description I hope it lead to the resolution
     
  • Suggested answer
    Ramesh Kumar Profile Picture
    7,503 Super User 2025 Season 2 on at
    Email Server Error Code: Http server returned Unauthorized exception (Exchnage & D365) on prem

    Check the Service Account Credentials

    Ensure the username and password for the Email Server Profile are 100% correct.

    If using OAuth, verify token scopes and expiration. EWS Authentication Mode. EWS on Exchange might be enforcing NTLM, Basic Auth, or OAuth2. Dynamics 365 On-Premises doesn’t support OAuth with Exchange Online. If you’ve moved to Modern Auth in Exchange, CRM will fail unless patched or reconfigured. Ensure Basic Authentication is enabled on Exchange (if still allowed). If using a service account, test with a tool like EWS Editor using the same credentials and impersonation settings.

    Thanks
    Ramesh
     
    If this was helpful, please check the "Does this answer your question?" box and mark it as verified.
  • Suggested answer
    Daivat Vartak (v-9davar) Profile Picture
    7,827 Super User 2025 Season 2 on at
    Email Server Error Code: Http server returned Unauthorized exception (Exchnage & D365) on prem
    Hello Abanoub_Techtrack,
     

    This is a frustrating situation, especially when basic connectivity seems fine but the CRM integration fails with an "Unauthorized" error. The fact that Telnet works and the connection tool is successful points to an issue specifically with how Dynamics 365 is authenticating against Exchange Web Services (EWS).

    Here's a breakdown of potential causes and troubleshooting steps, going beyond basic impersonation checks:

    Likely Causes (Beyond Basic Impersonation):

    1. Authentication Protocol Mismatch:

      • Modern Authentication vs. Basic Authentication: Dynamics 365 v9.1 might be attempting to use a different authentication protocol than what Exchange is expecting or allowing for EWS access. Exchange Online often defaults to Modern Authentication, while on-prem Exchange might have specific configurations. Ensure both systems are configured for a compatible protocol.

      • Negotiate Authentication Issues: If using Negotiate (Kerberos), there might be issues with Service Principal Names (SPNs) configuration for the Exchange server or the CRM server. 

    2. Specific EWS Virtual Directory Authentication Settings:

      • The authentication methods enabled on the /EWS/Exchange.asmx virtual directory in IIS on your Exchange server are critical. Verify that the authentication method being used by Dynamics 365 (likely Basic or Windows Integrated Authentication if impersonation is configured) is enabled on this virtual directory. 

    3. Incorrect Credentials Being Passed (Despite Impersonation):

      • Even with correct impersonation setup, the credentials used by the CRM service account to initially authenticate to Exchange might be incorrect or have insufficient permissions. 

    4. TLS/SSL Configuration Issues:

      • While less likely to cause an "Unauthorized" error directly, mismatches in TLS/SSL protocols or certificate issues could sometimes manifest in unexpected authentication failures. Ensure both CRM and Exchange are using compatible TLS versions and that the certificate on the Exchange server is trusted by the CRM server. 

    5. Proxy Server Interference:

      • If there's a proxy server between your CRM on-prem server and your Exchange on-prem server, it might be interfering with the authentication process or stripping necessary headers. Ensure the proxy is configured to allow the necessary traffic and authentication methods. 

    6. Network Load Balancer Issues (If Applicable):

      • If you have a network load balancer in front of your Exchange servers, it might be misdirecting or altering the authentication requests. 

    7. CRM Email Connector Configuration:

      • Double-check the specific configuration of the Email Server Profile in Dynamics 365. Ensure the "Authentication Type" and any associated credentials are configured correctly for your on-prem Exchange environment. 

    8. Time Synchronization Issues:

      • Significant time differences between the CRM and Exchange servers can sometimes cause authentication failures, especially with Kerberos. Ensure both servers have their clocks synchronized.


      •  

    9.  

    Detailed Troubleshooting Steps:

    1. Verify EWS Virtual Directory Authentication:

      • On your Exchange server, open IIS Manager.

      • Navigate to Servers > Sites > Default Web Site (or your Exchange website) > EWS.

      • Select the Exchange virtual directory.

      • Open Authentication.

      • Ensure that either Basic Authentication or Windows Authentication (or both, depending on your CRM configuration) are enabled. If using Windows Authentication, ensure the appropriate providers (Negotiate, NTLM) are configured.

      • If you made any changes, restart IIS. 

    2. Review CRM Email Server Profile Authentication:

      • In Dynamics 365, go to Settings > Email Configuration > Email Server Profiles.

      • Open the Email Server Profile for your Exchange on-prem setup.

      • Verify the Authentication Type selected. It should align with the authentication methods enabled on the EWS virtual directory.

      • If using Credentials Specified by User or Queue, ensure the correct username and password for the impersonated account are entered and are valid.

      • If using Credentials Specified in Email Server Profile, ensure the service account credentials used here have the necessary permissions. 

    3. Check SPN Configuration (If Using Negotiate/Kerberos):

       

      • On the Exchange server, open Command Prompt as Administrator and run: setspn -L <ExchangeServerName>

      • Verify that the HTTP/FQDNofYourExchangeServer and HTTP/<NetBIOSNameOfYourExchangeServer> SPNs are registered to the Exchange server's computer account or the appropriate service account if one is used for Exchange services.

      • On the CRM server, run: setspn -L <CRMServerName>

      • Ensure the necessary SPNs for the CRM services are correctly registered.

      • If SPNs are missing or incorrect, use setspn -S <SPN> <Account> to register them.

    4. Examine IIS Logs on the Exchange Server:

       

      • Check the IIS logs for the /EWS/Exchange.asmx requests originating from your CRM server. Look for 401 Unauthorized errors and examine the authentication headers being presented. This can provide more detailed information about why the authentication is failing. The logs are typically located in C:\inetpub\logs\LogFiles\W3SVC1\ (the W3SVC number might vary).

    5. Use Network Tracing Tools (e.g., Wireshark):

       

      • Run a network trace on the CRM server while attempting to connect to Exchange. Analyze the HTTP requests and responses to the /EWS/Exchange.asmx endpoint. This will show the exact authentication headers being sent and the server's response.

    6. Test with a Different Impersonated User:

       

      • Try configuring the Email Server Profile with a different user account that has full mailbox access and impersonation rights on the Exchange server to see if the issue is specific to a particular user account.

    7. Review Event Logs on Both CRM and Exchange Servers:

      • Check the System and Application event logs on both the Dynamics 365 server and the Exchange server for any relevant error messages or warnings related to authentication or EWS. 

      •  

    Given that the connection tool works and Telnet is fine, the issue is almost certainly related to the specific authentication context and headers being used by the Dynamics 365 application when it sends the POST request to Exchange.asmx. Focus your investigation on the authentication methods enabled on the EWS virtual directory and the credentials being used by the CRM Email Connector.

    Since you have an open ticket with support, provide them with the detailed findings from these additional troubleshooting steps. This will give them more specific information to work with and hopefully expedite a resolution. Good luck!

     
    If my answer was helpful, please click Like, and if it solved your problem, please mark it as verified to help other community members find more. If you have further questions, please feel free to contact me.
     
    My response was crafted with AI assistance and tailored to provide detailed and actionable guidance for your Microsoft Dynamics 365 query.
     
    Regards,
    Daivat Vartak

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Andrés Arias – Community Spotlight

We are honored to recognize Andrés Arias as our Community Spotlight honoree for…

Leaderboard > Microsoft Dynamics 365 | Integration, Dataverse, and general topics

#1
DAnny3211 Profile Picture

DAnny3211 367

#2
Abhilash Warrier Profile Picture

Abhilash Warrier 137 Super User 2025 Season 2

#3
Martin Dráb Profile Picture

Martin Dráb 82 Most Valuable Professional

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans