davmail icon indicating copy to clipboard operation
davmail copied to clipboard

How to configure davmail to get access to login.microsoftonline.com

Open ericxuo opened this issue 2 years ago • 7 comments

Hi,

Up to a few months ago, I could connect to my company Outlook EWS server using : davmail.server=true davmail.allowRemote=true davmail.mode=EWS davmail.url=https://outlook.office365.com/EWS/Exchange.asmx davmail.enableEws=true

Now, my company has blocked/removed/disabled the access to https://outlook.office365.com/EWS/Exchange.asmx

If I want to do it manually, I need to go to : https://login.microsoftonline.com Then I enter my work email address, my work email password, then I need to approve the connection on my phone, ...

When I'm connected, I get an url like : https://login.microsoftonline.com/common/oauth2/authorize?client_id=xyz-xyz-xyz-xyz-xyzxyzxyz&redirect_uri=https%3A%2F%2Fwww.office.com%2Flanding ... and much more

Could you help me to define the different variables I need to set in my davmail.properties to be able to connect to my Outlook mailbox ?

Trying : davmail.url=https://outlook.office365.com/EWS/Exchange.asmx davmail.oauth.redirectUri=https://login.microsoftonline.com/common/oauth2/nativeclient davmail.mode=O365Interactive # I don't know what to fill here : davmail.oauth.clientId=xyz-xyz-xyz-xyz-xyzxyzxyz davmail.enableEws=true

does not work.

Regards.

Xuo.

ericxuo avatar Feb 19 '23 11:02 ericxuo

With an empty clientId DavMail will use its own clientId (registered by me to have access to EWS endpoint).

If this doesn't work your best bet is Outlook desktop clientId:

davmail.oauth.redirectUri=urn:ietf:wg:oauth:2.0:oob davmail.oauth.clientId=d3590ed6-52b3-4102-aeff-aad2292ab01c

Then O365Interactive may or may not work depending on tenant security policies. If it doesn't work switch to O365Manual and authenticate in native browser registered with Azure AD.

If authentication is successful the code is available in the last http request.

mguessan avatar Mar 25 '23 15:03 mguessan

Everyone please have a look at: https://github.com/mguessan/o365psauth

I managed to write a simple powershell script to go through the O365 authentication using Webview2 - Edge chromium native web engine - to get that authentication code

Just grab the package, open powershell and run .\o365psauth.ps1 If everything goes as expected you will get the code on console, just paste it in DavMail O365Manual dialog window.

mguessan avatar Jan 19 '24 09:01 mguessan