reddit / emacs

Success stories setting up mu4e for Outlook with 2FA?

da-g · 2022-04-19 13:23
Hi guys, i can not longer use mu4e with my outlook account because of 2FA. I used to set it up through a combo of [DavMail](https://davmail.sourceforge.net/) and [offlineimap3](https://github.com/OfflineIMAP/offlineimap3), but now that doesn't work because DavMail can no longer create a bridge between outlook and imap, since I don' know how to get it working with 2FA. I was wondering if anyone has faced this problem before, or has any alternative suggestions. Were you too forced to give up on Emacs for mail?
robstewartUK · 2022-04-19 13:36
Hi! In January I wrote a blog post about this very topic: **Microsoft OAuth authentication with mu4e in Emacs** [https://www.macs.hw.ac.uk/\~rs46/posts/2022-01-11-mu4e-oauth.html](https://www.macs.hw.ac.uk/~rs46/posts/2022-01-11-mu4e-oauth.html) Please let me know if you are unable to follow any of these instructions.
mclearc · 2022-04-19 14:08
I use mu4e/mbsync and davmail with 2FA -- what was giving you trouble exactly?
ndpian · 2022-04-19 19:26
Davmail works for me in 2FA as well, using it with mu4e/mbsync. Following properties helped : davmail.mode=O365Manual davmail.url=https://outlook.office365.com/EWS/Exchange.asmx davmail.oauth.redirectUri=https://login.microsoftonline.com/common/oauth2/nativeclient another trick that helped: instead of starting in server mode, start in GUI mode, let Davmail configure the 2FA (and you allow it using the browser) and then export the properties into `davmail.properties` to run it subsequently in non-gui mode (`davmail.server=false`). This resulted in a `davmail.oath<your email>.refreshToken` field, which it uses to restore the connection subsequently.
JustinSilverman · 2022-04-19 20:27
FYI Many users don't have privileges to create a new application on azure. Large corporations and universities tend to lock that down.
Coolneng · 2022-04-19 22:02
I had the same problem, but I was able to use [Thunderbird's credentials](https://hg.mozilla.org/comm-central/file/tip/mailnews/base/src/OAuth2Providers.jsm)
da-g · 2022-04-20 04:41
Authentication fails =/
da-g · 2022-04-20 12:31
This is awesome, unfortunately offlineimap fails with LIST command error: BAD \[b'User is authenticated but not connected.'\], even though oauth2ms works. Have you ever had this happen to you?
da-g · 2022-04-20 12:32
What are you supposed to see in the authentication window?
mythenmetz68 · 2022-04-20 20:20
Nothing. It should be an empty page. davmail just needs the url for the page..
ndpian · 2022-04-20 23:14
Yeah it should be a blank page, and you should copy the url
da-g · 2022-04-21 00:31
my friend, this is golden. It works!! Thank you!
robstewartUK · 2022-04-22 11:54
>User is authenticated but not connected Sorry I can't help, I've not seen this error before. Are you still facing this issue?
da-g · 2022-04-23 20:12
I went the davmail route instead and got email to work again. I think the issue was on the creation of the app on azure, not sure I got all settings right.
JustinSilverman · 2022-05-02 22:40
Would you be willing to share your .davmail.properties (probably with your personal oath token XXX'd)? I am having troubl.e getting that working.
Coolneng · 2022-05-02 23:43
My setup is a bit different as I don't use davmail, I use mbsync + neomutt instead of offlineimap + mu4e but it can be adapted. I based my setup on [this article](https://www.vanormondt.net/~peter/blog/2021-03-16-mutt-office365-mfa.html), as you can see the oauth2 token is obtained via [this script](https://gitlab.com/muttmua/mutt/-/blob/master/contrib/mutt_oauth2.py), where you have to modify the variables as the article indicates (they're the same Thunderbird credentials that I linked to in my previous comment). In my case, I just use this script as a password in [mbsync](https://git.coolneng.duckdns.org/coolneng/dotfiles/src/commit/1032a7fb6aaed9dc8b721356393a6361d40b5c4e/mbsync/.mbsyncrc) and [msmtp](https://git.coolneng.duckdns.org/coolneng/dotfiles/src/commit/1032a7fb6aaed9dc8b721356393a6361d40b5c4e/msmtp/.msmtprc) for my university account (UGent). As a last thing, if you want to use mbsync you need to install [this plugin to enable OAUTH2](https://github.com/moriyoshi/cyrus-sasl-xoauth2), this is not needed for offlineimap as it supports OAUTH2 out of the box. My setup can be a bit overwhelming, feel free to ask me about it and I can elaborate more
JustinSilverman · 2022-05-05 00:03
Thank you!
JustinSilverman · 2022-05-05 00:09
I am unclear on how you use that plugin with mbsync. Could you explain?
Coolneng · 2022-05-05 00:39
Sure, you only need to install the program (either compiling from source or maybe it's available in your package manager repository) and then in mbsync you add the line ```AuthMechs XOAUTH2```, you can [see it here in my dotfiles](https://git.coolneng.duckdns.org/coolneng/dotfiles/src/commit/1032a7fb6aaed9dc8b721356393a6361d40b5c4e/mbsync/.mbsyncrc#L60)
JustinSilverman · 2022-05-10 23:03
By the way I know it's delayed but thank you!
Coolneng · 2022-06-08 18:21
I'm glad to have helped you, I hope it all worked out in the end