I have been using gnus for my various email accounts for years, but now my university has moved to outlook.office365 which requires oauth2. I can see that there is an oauth2 package for emacs, but no examples on its use nor how one might combine with gnus. And while I can see some online examples of people using offlineimap oauth2 with gmail I have not seen it for MS o365. Apparently Thunderbird can use oauth2. Has anyone had success with any of the emacs email applications (but gnus preferred)? If so, can you give some suggestions please? If not, any ideas how to figure out what Thunderbird is doing so that it might be emulated in gnus. Even a simple walkthrough the oauth2 package would be helpful.
Please see the gnus-o365-oauth2 module i just posted. I'll quote the intro from the comments below.
It works, but far from perfectly,
oauth2/plstore/gnupg stores the access tokens retrieved in an encrypted file but either the setting to have
plstore cache the passphrase for the encrypted file doesn't work or
gnupg keeps inventing new keys to store the access tokens under or something along those lines, whatever the cause the result is that
oauth2/plstore/gnupg causes recurring popups to inquire about a passphrase a few times per hour. Answer something you can type quickly and tick the box to save it for the least possible inconvenience.
Here's the intro to the module:
oauth2 tweaked to accept an optional function argument
read-authorization-string for the functions that invoke
see this repo for now.
- Obtain Office 365 tenant id:
Set tenant id:
(setq gnus-o365-oauth2-tenant-id "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx")
Obtain client identifier:
The client-secret may very well not be called for. Ask your Exchange administrator or someone else that has access to the "App registrations experience in the Azure portal", see: https://docs.microsoft.com/en-us/azure/active-directory/develop/v2-oauth2-auth-code-flow#request-an-authorization-code https://docs.microsoft.com/en-us/azure/active-directory/develop/active-directory-v2-protocols#app-registration https://aka.ms/appregistrations
Set client identifier(s):
(setq gnus-o365-oauth2-client-id "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx") (setq gnus-o365-oauth2-client-secret "xxxx")
Set custom authenticator:
(require 'oauth2) (require 'gnus-o365-oauth2) ; must be loaded *after* (setq gnus-o365-oauth2-*) (advice-add 'nnimap-login :before-until #'gnus-o365-oauth2-imap-authenticator)
plstore to save access tokens in
which is gpg-encrypted. This allows the gpg passphrase to be cached
during the Emacs session:
(setq plstore-cache-passphrase-for-symmetric-encryption t)
I have had success with gnus with the following configuration.
(setq message-send-mail-function 'smtpmail-send-it smtpmail-default-smtp-server "smtp.office365.com" smtpmail-smtp-server "smtp.office365.com" user-mail-address "<your mail address>" smtpmail-smtp-service 587 smtpmail-stream-type 'starttls )
(setq smtpmail-stream-type 'tls) does not work.
I was led to try this configuration based on this info.