harishkrupo / oauth2ms

Apache License 2.0
75 stars 24 forks source link

Adding smtp after using oauth2 for imap #21

Closed dschwilk closed 2 years ago

dschwilk commented 2 years ago

Thank you for oauth2ms! This helped me continue to use emacs mbsync and mu4e when my university forced oauth2 imap this summer. At that time, smtp did not yet require oauth2 so I did not add code to my mu4e setup to use oauth2. That changed today. Therefore, I added to my .emacs based on the code in steps.org. I also made sure the config.json file had

   "scopes": ["https://outlook.office365.com/IMAP.AccessAsUser.All", "https://outlook.office365.com/SMTP.Send"]

And I had already set the smtp permissions in azure.

But attempting to send smtp results in an smtp trace like shown below (I deleted the token string). Any suggestion on where to start?

220 SN7P220CA0005.outlook.office365.com Microsoft ESMTP MAIL Service ready at Mon, 3 Oct 2022 15:50:36 +0000
250-SN7P220CA0005.outlook.office365.com Hello [<ip address>]
250-SIZE 157286400
250-PIPELINING
250-DSN
250-ENHANCEDSTATUSCODES
250-STARTTLS
250-8BITMIME
250-BINARYMIME
250-CHUNKING
250 SMTPUTF8
220 2.0.0 SMTP server ready
250-SN7P220CA0005.outlook.office365.com Hello [<ip address>]
250-SIZE 157286400
250-PIPELINING
250-DSN
250-ENHANCEDSTATUSCODES
250-AUTH LOGIN XOAUTH2
250-8BITMIME
250-BINARYMIME
250-CHUNKING
250 SMTPUTF8
AUTH XOAUTH2 

[TOKEN CHUNK HERE DELETED]

535 5.7.3 Authentication unsuccessful [SN7P220CA0005.NAMP220.PROD.OUTLOOK.COM]
QUIT
221 2.0.0 Service closing transmission channel
nbarrientos commented 2 years ago

Try removing the credentials cache (this will remove your refresh token) and getting a new one.

$ rm ~/.local/share/oauth2ms/credentials.bin

and then execute oauth2ms again.

dschwilk commented 2 years ago

Luckily I just moved the credentials.bin out of the way. Something seems to have changed and new credentials do not download. I am getting webpage with "Authorization complete" as reported in #22 and no new credentials.bin ... imap at least working with the old credentials.bin

dschwilk commented 2 years ago

Thank you @nbarrientos for this. A new refresh token was what was needed. The reason this did not work immediately for me was my own carelessness: in previous testing and experimenting I had put the wrong url for the smtp scope in config.json. For my setup it needed to be

"scopes": ["https://outlook.office365.com/IMAP.AccessAsUser.All","https://outlook.office365.com/SMTP.Send"]

Although the localhost webpage that oath2ms returned stated "Authorization complete.", the url string showed that it had not worked eg:

The+resource+principal+named+https%3a%2f%2fsmtp.office365.com+was+not+found+in+the+tenant+named ...