向 Office 365 SMTP 的 Azure 应用程序添加 SMTP.Send 权限时出现问题

问题描述 投票:0回答:1

我正在 Azure 门户上开发一个应用程序,以使用 SMTP 服务器 smtp.office365.com 通过免费 Microsoft 帐户发送电子邮件。

如何将权限 https://outlook.office.com/SMTP.Send 添加到 Azure 门户上的应用程序?我找不到这个选项,只有https://outlook.office.com/Mail.Send

解决方法是在启动身份验证过程时在“范围”中添加 https://outlook.office.com/SMTP.Send,但我想使用 https://outlook.office.com/。默认,因为还有其他所需的权限。换句话说,https://outlook.office.com/SMTP.Send存在并且可以工作,但在门户界面中不可用。

我尝试使用 https://graph.microsoft.com/SMTP.Send 代替,但在尝试向 SMTP 发送电子邮件时出现授权错误。

azure oauth-2.0 smtp
1个回答
0
投票

我同意您的观点,

SMTP.Send
API 权限在 Microsoft Entra ID 应用程序的 API 权限刀片中不可用。请参阅 Allen Wu 的 SO 主题

enter image description here

因此,作为解决方法,您需要指定范围名称来生成令牌,如

https://outlook.office.com/SMTP.Send

对于 sample,我生成了以下 API 权限:

enter image description here

并将 scope 作为

https://outlook.office.com/SMTP.Send
传递以生成访问令牌:

GET https://login.microsoftonline.com/<tenant_id>/oauth2/v2.0/token 
client_id=ClientID
client_secret = ClientSecret
redirect_uri= https://jwt.ms
code=Code
scope= https://outlook.office.com/SMTP.Send 
grant_type = authorization_code

访问令牌包含授予 Microsoft Entra ID 应用程序的所有 Office 365 Exchange Online 权限

enter image description here

解码后,存在范围,即

SMTP.Send
以及授予 Microsoft Entra ID 应用程序的所有其他权限。

enter image description here

如果问题仍然存在,传递如下所示的单独范围:

scope : https://outlook.office.com/SMTP.Send https://outlook.office.com/Mail.Send https://outlook.office.com/Calendars.Read.All

enter image description here

© www.soinside.com 2019 - 2024. All rights reserved.