I'm having an issue with SMTP/IMAP via XOAUTH2. I've created a Microsoft Entra ID service, connected it via API, and appropriately configured the Graph API to be able to access SMTP/IMAP.
During authorization, I'm initially using the following scopes:
'User.Read',
'SMTP.Send',
'IMAP.AccessAsUser.All',
'email',
'offline_access',
'openid',
'profile',
'Mail.Send',
'https://outlook.office.com/SMTP.Send',
'https://outlook.office.com/IMAP.AccessAsUser.All',
'offline_access'
And after logging in, I receive data in this format:
+id: "4903......9094"
+nickname: null
+name: "M.......ki"
+email: "m........375.onmicrosoft.com"
+avatar: null
+token: "eyJ0e......hIYm5BdyIsImtp ▶"
+refreshToken: "0.A......Y4om ▶"
+expiresIn: 3868
+approvedScopes: null
+accessTokenResponseBody: array:7 [▼
"token_type" => "Bearer"
"scope" => "email IMAP.AccessAsUser.All Mail.Send openid profile SMTP.Send User.Read"
"expires_in" => 3868
"ext_expires_in" => 3868
"access_token" => "eyJ0e...laA ◀"
"refresh_token" => "0.Aa4Ai...6t60Y4om ▶"
"id_token" => "eyJ...JodHR ▶"
]
It seems like the data is okay so far. Now, I want to use XOAUTH2 and I'm trying to connect following these instructions: https://learn.microsoft.com/en-us/exchange/client-developer/legacy-protocols/how-to-authenticate-an-imap-pop-smtp-application-by-using-oauth
For SMTP, I've tried using the base64 encoding of the email field from the response as well as the token field, but I noticed that the API returned my email address changed under the onmicrosoft.com domain, so I also tried using my email address.
After encoding and connecting to XOAUTH2, I receive a server response of "250 Resetting" - why is that? Can you suggest what I might be doing wrong?
Thank you :)
PS. I've added the same account to Thunderbird by going through the Microsoft auth page, and it seems like everything is okay there (I can access my mailbox normally from Thunderbird).