a demo of python sending emails with Oauth for China Office365.
- 2023/09/13 update: add imap authentication code.
- only working for China Office 365.
- i'm using python MSAL auth library. https://learn.microsoft.com/en-us/python/api/overview/azure/active-directory?view=azure-python
- MUST replace
^A
to\x01
from official docs. Authenticate an IMAP, POP or SMTP connection using OAuth
xoauth = base64("user=" + userName + "\x0auth=Bearer " + accessToken + "\x01")
.
.
.
smtp_conn.docmd('AUTH', 'XOAUTH2 ' + xoauth)
imap.authenticate('XOAUTH2', lambda x: 'user={}\x01auth=Bearer {}\x01\x01'.format(email, accesstoken))