我在通过 PHPMail 发送 SMTP 邮件期间遇到 OAuth 2.0 授权问题。
基本上,我已经尝试了下面列出的所有范围:
email
openid
profile
https://graph.microsoft.com/Mail.Send
https://graph.microsoft.com/SMTP.Send
https://graph.microsoft.com/User.Read
User.Read
SMTP.Send
Mail.Send
offline_access
使用以下 Auth URI:
-
https://login.microsoftonline.com/common/oauth2/v2.0/token
with https://login.microsoftonline.com/common/oauth2/v2.0/authorize
-
https://login.microsoftonline.com/common/oauth2/token
with https://login.microsoftonline.com/common/oauth2/authorize
使用以下主机名:
smtp.office365.com
smtp.outlook.com
但没有任何效果。 :(
这是 PHPMailer 的详细输出:
2022-09-06 14:55:41 Connection: opening to smtp.office365.com:587, timeout=300, options=array()
2022-09-06 14:55:41 Connection: opened
2022-09-06 14:55:41 SMTP INBOUND: "220 BLAPR03CA0009.outlook.office365.com Microsoft ESMTP MAIL Service ready at Tue, 6 Sep 2022 14:55:40 +0000"
2022-09-06 14:55:41 SERVER -> CLIENT: 220 BLAPR03CA0009.outlook.office365.com Microsoft ESMTP MAIL Service ready at Tue, 6 Sep 2022 14:55:40 +0000
2022-09-06 14:55:41 CLIENT -> SERVER: EHLO <REMOVED_FOR_SECURITY_REASONS>.org
2022-09-06 14:55:41 SMTP INBOUND: "250-BLAPR03CA0009.outlook.office365.com Hello [150.136.30.43]"
2022-09-06 14:55:41 SMTP INBOUND: "250-SIZE 157286400"
2022-09-06 14:55:41 SMTP INBOUND: "250-PIPELINING"
2022-09-06 14:55:41 SMTP INBOUND: "250-DSN"
2022-09-06 14:55:41 SMTP INBOUND: "250-ENHANCEDSTATUSCODES"
2022-09-06 14:55:41 SMTP INBOUND: "250-STARTTLS"
2022-09-06 14:55:41 SMTP INBOUND: "250-8BITMIME"
2022-09-06 14:55:41 SMTP INBOUND: "250-BINARYMIME"
2022-09-06 14:55:41 SMTP INBOUND: "250-CHUNKING"
2022-09-06 14:55:41 SMTP INBOUND: "250 SMTPUTF8"
2022-09-06 14:55:41 SERVER -> CLIENT: 250-BLAPR03CA0009.outlook.office365.com Hello [150.136.30.43]250-SIZE 157286400250-PIPELINING250-DSN250-ENHANCEDSTATUSCODES250-STARTTLS250-8BITMIME250-BINARYMIME250-CHUNKING250 SMTPUTF8
2022-09-06 14:55:41 CLIENT -> SERVER: STARTTLS
2022-09-06 14:55:41 SMTP INBOUND: "220 2.0.0 SMTP server ready"
2022-09-06 14:55:41 SERVER -> CLIENT: 220 2.0.0 SMTP server ready
2022-09-06 14:55:41 CLIENT -> SERVER: EHLO <REMOVED_FOR_SECURITY_REASONS>.org
2022-09-06 14:55:41 SMTP INBOUND: "250-BLAPR03CA0009.outlook.office365.com Hello [150.136.30.43]"
2022-09-06 14:55:41 SMTP INBOUND: "250-SIZE 157286400"
2022-09-06 14:55:41 SMTP INBOUND: "250-PIPELINING"
2022-09-06 14:55:41 SMTP INBOUND: "250-DSN"
2022-09-06 14:55:41 SMTP INBOUND: "250-ENHANCEDSTATUSCODES"
2022-09-06 14:55:41 SMTP INBOUND: "250-AUTH LOGIN XOAUTH2"
2022-09-06 14:55:41 SMTP INBOUND: "250-8BITMIME"
2022-09-06 14:55:41 SMTP INBOUND: "250-BINARYMIME"
2022-09-06 14:55:41 SMTP INBOUND: "250-CHUNKING"
2022-09-06 14:55:41 SMTP INBOUND: "250 SMTPUTF8"
2022-09-06 14:55:41 SERVER -> CLIENT: 250-BLAPR03CA0009.outlook.office365.com Hello [150.136.30.43]250-SIZE 157286400250-PIPELINING250-DSN250-ENHANCEDSTATUSCODES250-AUTH LOGIN XOAUTH2250-8BITMIME250-BINARYMIME250-CHUNKING250 SMTPUTF8
2022-09-06 14:55:41 Auth method requested: XOAUTH2
2022-09-06 14:55:41 Auth methods available on the server: LOGIN,XOAUTH2
2022-09-06 14:55:41 CLIENT -> SERVER: AUTH XOAUTH2 <TOKEN REMOVED FOR SECURITY REASONS>
2022-09-06 14:55:47 SMTP INBOUND: "535 5.7.3 Authentication unsuccessful [BLAPR03CA0009.namprd03.prod.outlook.com]"
2022-09-06 14:55:47 SERVER -> CLIENT: 535 5.7.3 Authentication unsuccessful [BLAPR03CA0009.namprd03.prod.outlook.com]
2022-09-06 14:55:47 SMTP ERROR: AUTH command failed: 535 5.7.3 Authentication unsuccessful [BLAPR03CA0009.namprd03.prod.outlook.com]
SMTP Error: Could not authenticate.
2022-09-06 14:55:47 CLIENT -> SERVER: QUIT
2022-09-06 14:55:47 SMTP INBOUND: "221 2.0.0 Service closing transmission channel"
2022-09-06 14:55:47 SERVER -> CLIENT: 221 2.0.0 Service closing transmission channel
2022-09-06 14:55:47 Connection: closed
SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting
Mailer Error: SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting
这是var_dump
由 Steven Maguire 的 Provider 处理的访问令牌变量:
object(League\OAuth2\Client\Token\AccessToken)#33 (5) {
["accessToken":protected]=>
string(2012) "<TOKEN REMOVED FOR SECURITY REASONS>"
["expires":protected]=>
int(1662481291)
["refreshToken":protected]=>
string(848) "<TOKEN REMOVED FOR SECURITY REASONS>"
["resourceOwnerId":protected]=>
NULL
["values":protected]=>
array(3) {
["token_type"]=>
string(6) "Bearer"
["scope"]=>
string(134) "email openid profile https://graph.microsoft.com/Mail.Send https://graph.microsoft.com/SMTP.Send https://graph.microsoft.com/User.Read"
["ext_expires_in"]=>
int(5150)
}
}
有趣的是 PHPMailer 的内部代码建议使用wl.offline_access
and wl.imap
,以及大多数建议的操作方法wl.basic
and wl.emails
。这些范围是已弃用.
你能帮我吗?
None
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)