mguessan / davmail

DavMail POP/IMAP/SMTP/Caldav/Carddav/LDAP Exchange and Office 365 Gateway - Synced with main subversion repository at
http://davmail.sourceforge.net
GNU General Public License v2.0
580 stars 86 forks source link

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

Open ericxuo opened 1 year ago

ericxuo commented 1 year ago

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.

mguessan commented 1 year ago

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 commented 10 months ago

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.