Closed tks-socius closed 2 years ago
I haven't tried using the acquired access token (AT) in an SMTP session. Would you mind checking out from the SMTP side of docs to see what credential does SMTP accept? Traditionally, SMTP session would require the end user password, and a send mail Graph API would require an OAuth2 access token. They are different, unless an SMTP service explicitly documents that you could use an AT as SMTP password.
This sample utilizes the MSAL library to get you an AT, and AT only.
Besides the comment above, it seems the StackOverflow community answered your question since then. Please follow up there.
I have used this app (downloaded from the AAD portal with my secret in it) and tried to use the given token for SMTP authentication, using the information from
Logging in with my office email account works and the
/graphcall
works as well. However the SMTP authentication is not working, I am receivingreply: retcode (535); Msg: b'5.7.3 Authentication unsuccessful [LO2P265CA0061.GBRP265.PROD.OUTLOOK.COM]'
from it.The Scope of the token that I am asking for is
SCOPE = ["User.ReadBasic.All", "https://outlook.office.com/SMTP.Send"]
and the app hasSMTP.send
turned on in the config fileHere is a class extending
smtplib.SMTP
that I have written based on those:and the code to connect with the credentials from the app here, and adding a page where I display the token json for a sanity check:
The authentication is failing, here is the full log:
things I have cheeked:
FYI the token data looks like this, with the tokens and username removed