UvA-FNWI / M365-IMAP

MIT License
70 stars 17 forks source link

Support for exim SMTP (and also refresh token expiry) #16

Open clarified opened 1 year ago

clarified commented 1 year ago

Hello again,

I use exim for my outgoing email, and it does not (yet?) support OAUTH natively. I have now got it working with pretty much a 5 line gawk script, although there is a little more to it than that.

I started with exim4-oauth2 but that didn't work, and I don't understand how it could ever have worked, but adapted that approach for use with M365-IMAP.

You give instructions for msmtp. Would you like me to provide the instructions for exim as well?

In the course of getting exim to work with MS oauth, I came across a a statement from MS that refresh tokens expire after 90 days. You don't seem to allow for that: have I missed something?

I am planning to arrange to renew the refresh token every month or two in my gawk script, but haven't done that yet.

goomens commented 1 year ago

Yes, I think that would be useful! I'm not sure how refresh token expiry works in practice but renewing the token every so often is probably a good idea in any case.

clarified commented 1 year ago

I have now uploaded my project to github: oauth2ForExim.

It is designed to be used alongside M365-IMAP although it can be used independently. It caches both the refresh and access tokens. And looks after refresh token expiry by renewing the refresh token periodically. Currently roughly once a month.

The README.md file gives more detail.

clarified commented 1 year ago

s/github/gitlab/g !!

clarified commented 1 year ago

I just encountered refresh token expiry in my .offlinimaprc file for the first time. Fortunately I had a current refresh token cached in oauth2ForExim, so it was trivial to copy for offlineimaprc. offlineimap ddin't give a very clear message.

chris001 commented 1 year ago

Ideally, the code should try to detect xoauth2 login failure, and catch when the reason is expired token, renew it, and try again!

clarified commented 1 year ago

On Sat, Apr 22, 2023 at 10:39:19AM -0700, Chris Coleman wrote:

Ideally, the code should try to detect xoauth2 login failure, and catch when the reason is expired token, renew it, and try again!

Indeed, but I don't think that is possible because the failure happens in exim and there is no channnel back into the script. Well maybe there is a way using some sort of hook, but I have not explored that.

It seems that someone is trying to extend exim to handle oauth2 directly, so it would be much easier there. If they succeed, my code would become redundant.

ael

clarified commented 1 year ago

Please ignore my previous comment :-) I replied to the email copy without the context, and now realise that it was about M365-IMAP and not about oauthForExim.