535 5.7.3 Authentication unsuccessful [SI2PR06CA0012.apcprd06.prod.outlook.com

睚眦 0 信誉分
2025-04-28T02:49:21.93+00:00

I want to use OAuth authentication to connect with SMTP protocols and to send mail for Office 365 users on printer.

  1. I register my application with Microsoft Entra.

The permission requested by the application is Mail.Send,offline_access,SMTP.Send,User.Read.

2.Get an access token with OAuth2 device authorization grant flow.

post https://login.microsoftonline.com/common/oauth2/v2.0/devicecode

To sign in, use a web browser to open the page https://microsoft.com/devicelogin and enter the code XXXXXX to authenticate.

Use this account(******@outlook.com) to authenticate successfully.

post https://login.microsoftonline.com/common/oauth2/v2.0/tokenSuccessfully obtained the token.

The permission is Mail.Send,SMTP.Send.     

"token_type": "Bearer",    

"scope": "SMTP.Send Mail.Send",    

"expires_in": 3600,    

"ext_expires_in": 3600,   

 "access_token": "EwA4BMl6BAAUBKgm8k1UswUNwklmy2v7U/S+1fEAAb9XPqpV+OBTrTnCSfEoa4y9lzlLbRy/HGMJ...

  1. smtp server : smtp.office365.com , port 587, starttls.

I use SASL XOAUTH2 format to encode and transmit the access token. 

base64("user=" + userName + "^Aauth=Bearer " + accessToken + "^A^A").

The base64 decoded string is user=qiaXXXX^******@outlook.comauth=Bearer EwA4BMl6BAAUBKgm8k1UswUNwklmy2v7...^A^A

C: auth xoauth2

S: 334

C: dXNlcj1xaWFuNjY1MEBvdXRsb29rLmNvb...

S: 535 5.7.3 Authentication unsuccessful [SI2PR06CA0012.apcprd06.prod.outlook.com 2025-04-24T09:33:05.942Z 08DD81FD8DFF148B]

I have obtained a token and have been authenticated to have sufficient permissions. 

Why does the SMTP server fail to authenticate? Is there something wrong with my username? Or is there something wrong with the app settings? Or is there a token permission issue?

Microsoft Graph
Microsoft Graph
一种 Microsoft 可编程性模型,用于公开 REST API 和客户端库以访问 Microsoft 365 服务上的数据。
94 个问题
0 个注释 无注释
{count} 票

你的答案

问题作者可以将答案标记为“接受的答案”,这有助于用户了解已解决作者问题的答案。