Forum Discussion
please help with : The response received from the service didn't contain valid XM error
Hi Eddy-2023,
The error message you're encountering, "(401) Unauthorized," indicates that there is an issue with the authentication and authorization when your application is trying to access Office 365 services.
The "The response received from the service didn't contain valid XML" error suggests there might also be a problem with the response from the server.
Here are some steps to help you troubleshoot and resolve the issue:
1. Check Office 365 Credentials:
- Ensure that the email address and password you are using in your code are correct and have the necessary permissions to send emails on behalf of the specified account.
2. Use Autodiscover:
- Instead of hardcoding the URL, you can use Autodiscover to automatically discover the correct EWS endpoint URL. This is a more flexible and recommended approach.
service.AutodiscoverUrl("****email address removed for privacy reasons****");
Make sure your code uses the correct Autodiscover method.
3. Service Permissions:
- Verify that the account you're using to authenticate has the necessary permissions to access and send emails through the EWS. You might need to grant ApplicationImpersonation permissions.
4. Check if 2FA is disabled:
- Ensure that two-factor authentication (2FA) is disabled for the account you are using in your application. You mentioned that you've turned it off, but double-check to confirm.
5. Delegations and Permissions:
- Ensure that the permissions and delegations are set up correctly in Office 365 for the sending account.
6. URL and Endpoints:
- The URL you're using should point to the correct EWS endpoint. If Autodiscover doesn't work for some reason, try using a URL like: https://outlook.office365.com/EWS/Exchange.asmx.
7. Firewall and Network Issues:
- Make sure that there are no firewall or network-related issues that might be blocking outgoing requests from your server to Office 365 services. Verify that the server can reach the necessary endpoints.
8. Server Configuration:
- Check your Windows Server IIS configuration to ensure it's not blocking outbound requests to the Office 365 service. Make sure that the URL you are trying to access is not restricted by any URL filtering or proxy settings.
Please click Mark as Best Response & Like if my post helped you to solve your issue.
This will help others to find the correct solution easily. It also closes the item.
If the post was useful in other ways, please consider giving it Like.
Kindest regards,
Leon Pavesic
(LinkedIn)
- OdeneGerberNov 21, 2023Copper Contributor
New Error
Message Error: The request failed. The remote server returned an error: (401) Unauthorized.
It looks like the issue is in part 3 of the code?
Please can you confirm where in the code is the senders email?- LeonPavesicNov 21, 2023Silver Contributor
Hi OdeneGerber,
thanks for your update,It seems that the issue is still related to authentication, and the error "(401) Unauthorized" suggests that the credentials provided in your code are not being accepted by the server.
Let's review the code, particularly the section related to credentials:try { service.Credentials = new WebCredentials("****email address removed for privacy reasons****", "****userpassword****"); } catch (Exception ex) { return BadRequest("Credentials: " + ex.Message); }In this code block, you are setting the credentials for the `ExchangeService` using a username and password.
Ensure that:1. The email address and password provided are correct.
2. The account associated with the provided email address has the necessary permissions to send emails via EWS.
If the email address and password are correct, you may need to review the permissions and configuration on the Office 365 side. Here are a few steps to consider:1. Application Impersonation Permissions: Make sure that the account used in the credentials has ApplicationImpersonation permissions. This is necessary for sending emails on behalf of another user.
2. Check Account Permissions: Verify that the account has the required permissions to send emails using EWS. You might need to check the Exchange Online settings to grant the necessary permissions.
3. Use Autodiscover: As previously mentioned, consider using Autodiscover to automatically discover the correct EWS endpoint URL. Replace the hardcoded URL with:
service.AutodiscoverUrl("****email address removed for privacy reasons****");Make sure to update your code accordingly. Using Autodiscover can help ensure that your application is always using the correct EWS endpoint.
Please click Mark as Best Response & Like if my post helped you to solve your issue.
This will help others to find the correct solution easily. It also closes the item.If the post was useful in other ways, please consider giving it Like.
Kindest regards,
Leon Pavesic
(LinkedIn)