使用 ClientCredentialProvider 发送电子邮件时找不到租户 guid
Sending email using ClientCredentialProvider is failing to find tenant guid
我正在使用 Microsoft Identity 的 OAuth 2.0 支持来使用 Microsoft Graph 发送电子邮件。
创建了个人电子邮件帐户 XXXX@outlook.com。我使用此帐户登录到 Azure AD 并在那里创建一个租户。使用 ClientCredentialProvider
(来自 msgraph-sdk-auth-java)作为授权方尝试向自己发送电子邮件。
步骤:
- 创建了租户帐户。
- 创建应用程序并在 Graph>Application->Send.email 等中授予权限
- 创建了密钥
以下是我收到的错误:
POST microsoft.graph.sendMail
SdkVersion : graph-java/v1.5.0 Authorization : Bearer
_xv1yPye...
{
"message": {
"subject": "Test",
"body": {
"contentType": "text",
"content": "The new cafeteria is open bujji."
},
"toRecipients": [
{
"emailAddress": {
"address": "xxxxx@outlook.com"
}
}
]
},
"saveToSentItems": true
}401: UnauthorizedStrict-Transport-Security: max-age=31536000Cache-Control: privatex-ms-ags-diagnostic: {
"ServerInfo": {
"DataCenter": "South India",
"Slice": "SliceC",
"Ring": "3",
"ScaleUnit": "001",
"RoleInstance": "AGSFE_IN_1"
}
}client-request-id: 01565263-11b4-45f7-b089-06f57fdd8241request-id: 2e0cac3b-dc32-4dab-bb30-769590fc156eContent-Length: 361Date: Tue,
16Jun202007: 14: 42GMTContent-Type: application/json{
"error": {
"code": "OrganizationFromTenantGuidNotFound",
"message": "The tenant for tenant guid \u002706841624-5828-4382-b0a0-XXXXXX87b08f\u0027 does not exist.",
"innerError": {
"requestId": "01565263-11b4-45f7-b089-06f57fdd8241",
"date": "2020-06-16T07:14:43",
"request-id": "2e0cac3b-dc32-4dab-bb30-769590fc156e"
}
}
}
private static void sendEmail() {
ClientCredentialProvider authProvider = new ClientCredentialProvider(
"fb7f0ecc-b498-XXXX-XXXX-b016f252ea7d",
Arrays.asList("https://graph.microsoft.com/.default"),
"8-rpF8sOwV.CWF~7gK.XXXXXXXX.SSScxj0",
"06841624-5828-4382-b0a0-XXXXXXe87b08f",
NationalCloud.Global);
IGraphServiceClient graphClient = GraphServiceClient.builder().authenticationProvider(authProvider).buildClient();
Message message = new Message();
message.subject = "Test";
Ite * mBody body = new ItemBody();
body.contentType = BodyType.TEXT;
body.content = "The new cafeteria is open.";
message.body = body;
LinkedList < Recipient > toRecipientsList = new LinkedList < Recipient > ();
Recipient toRecipients = new Recipient();
EmailAddress emailAddress = new EmailAddress();
emailAddress.address = "xxxxx@outlook.com";
toRecipients.emailAddress = emailAddress;
toRecipientsList.add(toRecipients);
message.toRecipients = toRecipientsList;
graphClient.me()
.sendMail(message, true)
.buildRequest()
.post();
}
我猜您想使用 Microsoft Graph API 从您的个人帐户电子邮件 XXXX@outlook.com
发送电子邮件。
但是当您使用此帐户登录Azure AD并创建租户,并在您的代码中使用ClientCredentialProvider
时,该帐户将被视为您租户的工作帐户(而非个人帐户)。
因此,当工作帐户要发送电子邮件时,需要 O365 订阅的 Exchange 在线许可证。您没有包含 Exchange 在线许可证的 O365 订阅。这就是您收到此错误的原因:The tenant for tenant guid \u002706841624-5828-4382-b0a0-XXXXXX87b08f\u0027 does not exist.
如果您想从个人帐户发送电子邮件,则无需创建 AAD 租户。你应该使用 Authorization code provider rather than Client credentials provider. Another thing is that personal account requires Delegated permission rather than Application permission based on Send mail permissions。创建一个应用程序并在 Graph > Delegated > Mail.Send 中授予权限。
请注意,它可能需要范围 https://graph.microsoft.com/mail.send
而不是 https://graph.microsoft.com/.default
。
谢谢艾伦的帮助。我可以从我的 outlook 帐户发送和接收电子邮件。使用 授权代码提供商
1. 登录到 Azure AD 在 "Application from Personl account" 中创建一个应用程序。
2. 授予权限 Graph > Delegated > Mail.Send。
3.提供Redirect URL as http://localhost:8080/muapp”。记下所有appId,创建一个secret Key。
4.Now 点击下方 URL 并提供详细信息
https://login.microsoftonline.com/common/oauth2/v2.0/authorize?client_id=40fcd457-1807-49e3-8bce-XXXXXX40ca194&response_type=code&redirect_uri=https://localhost/myapp/&response_mode=query&scope=openid%20offline_access%20https%3A%2F%2Fgraph.microsoft.com%2Fmail.send%20https%3A%2F%2Fgraph.microsoft.com%2Fmail.read&state=12345
5。获取我们需要在Authorization code provider中传入的code.This代码。
6.Scope “https://graph.microsoft.com/mail.send”
7.权限“https://login.microsoftonline.com/consumers”
我每次发送电子邮件时都有一个问题,我必须获取代码。有什么方法可以让这个有有效期等吗???
我正在使用 Microsoft Identity 的 OAuth 2.0 支持来使用 Microsoft Graph 发送电子邮件。
创建了个人电子邮件帐户 XXXX@outlook.com。我使用此帐户登录到 Azure AD 并在那里创建一个租户。使用 ClientCredentialProvider
(来自 msgraph-sdk-auth-java)作为授权方尝试向自己发送电子邮件。
步骤:
- 创建了租户帐户。
- 创建应用程序并在 Graph>Application->Send.email 等中授予权限
- 创建了密钥
以下是我收到的错误:
POST microsoft.graph.sendMail SdkVersion : graph-java/v1.5.0 Authorization : Bearer _xv1yPye...
{
"message": {
"subject": "Test",
"body": {
"contentType": "text",
"content": "The new cafeteria is open bujji."
},
"toRecipients": [
{
"emailAddress": {
"address": "xxxxx@outlook.com"
}
}
]
},
"saveToSentItems": true
}401: UnauthorizedStrict-Transport-Security: max-age=31536000Cache-Control: privatex-ms-ags-diagnostic: {
"ServerInfo": {
"DataCenter": "South India",
"Slice": "SliceC",
"Ring": "3",
"ScaleUnit": "001",
"RoleInstance": "AGSFE_IN_1"
}
}client-request-id: 01565263-11b4-45f7-b089-06f57fdd8241request-id: 2e0cac3b-dc32-4dab-bb30-769590fc156eContent-Length: 361Date: Tue,
16Jun202007: 14: 42GMTContent-Type: application/json{
"error": {
"code": "OrganizationFromTenantGuidNotFound",
"message": "The tenant for tenant guid \u002706841624-5828-4382-b0a0-XXXXXX87b08f\u0027 does not exist.",
"innerError": {
"requestId": "01565263-11b4-45f7-b089-06f57fdd8241",
"date": "2020-06-16T07:14:43",
"request-id": "2e0cac3b-dc32-4dab-bb30-769590fc156e"
}
}
}
private static void sendEmail() {
ClientCredentialProvider authProvider = new ClientCredentialProvider(
"fb7f0ecc-b498-XXXX-XXXX-b016f252ea7d",
Arrays.asList("https://graph.microsoft.com/.default"),
"8-rpF8sOwV.CWF~7gK.XXXXXXXX.SSScxj0",
"06841624-5828-4382-b0a0-XXXXXXe87b08f",
NationalCloud.Global);
IGraphServiceClient graphClient = GraphServiceClient.builder().authenticationProvider(authProvider).buildClient();
Message message = new Message();
message.subject = "Test";
Ite * mBody body = new ItemBody();
body.contentType = BodyType.TEXT;
body.content = "The new cafeteria is open.";
message.body = body;
LinkedList < Recipient > toRecipientsList = new LinkedList < Recipient > ();
Recipient toRecipients = new Recipient();
EmailAddress emailAddress = new EmailAddress();
emailAddress.address = "xxxxx@outlook.com";
toRecipients.emailAddress = emailAddress;
toRecipientsList.add(toRecipients);
message.toRecipients = toRecipientsList;
graphClient.me()
.sendMail(message, true)
.buildRequest()
.post();
}
我猜您想使用 Microsoft Graph API 从您的个人帐户电子邮件 XXXX@outlook.com
发送电子邮件。
但是当您使用此帐户登录Azure AD并创建租户,并在您的代码中使用ClientCredentialProvider
时,该帐户将被视为您租户的工作帐户(而非个人帐户)。
因此,当工作帐户要发送电子邮件时,需要 O365 订阅的 Exchange 在线许可证。您没有包含 Exchange 在线许可证的 O365 订阅。这就是您收到此错误的原因:The tenant for tenant guid \u002706841624-5828-4382-b0a0-XXXXXX87b08f\u0027 does not exist.
如果您想从个人帐户发送电子邮件,则无需创建 AAD 租户。你应该使用 Authorization code provider rather than Client credentials provider. Another thing is that personal account requires Delegated permission rather than Application permission based on Send mail permissions。创建一个应用程序并在 Graph > Delegated > Mail.Send 中授予权限。
请注意,它可能需要范围 https://graph.microsoft.com/mail.send
而不是 https://graph.microsoft.com/.default
。
谢谢艾伦的帮助。我可以从我的 outlook 帐户发送和接收电子邮件。使用 授权代码提供商 1. 登录到 Azure AD 在 "Application from Personl account" 中创建一个应用程序。 2. 授予权限 Graph > Delegated > Mail.Send。 3.提供Redirect URL as http://localhost:8080/muapp”。记下所有appId,创建一个secret Key。 4.Now 点击下方 URL 并提供详细信息
https://login.microsoftonline.com/common/oauth2/v2.0/authorize?client_id=40fcd457-1807-49e3-8bce-XXXXXX40ca194&response_type=code&redirect_uri=https://localhost/myapp/&response_mode=query&scope=openid%20offline_access%20https%3A%2F%2Fgraph.microsoft.com%2Fmail.send%20https%3A%2F%2Fgraph.microsoft.com%2Fmail.read&state=12345
5。获取我们需要在Authorization code provider中传入的code.This代码。 6.Scope “https://graph.microsoft.com/mail.send” 7.权限“https://login.microsoftonline.com/consumers”
我每次发送电子邮件时都有一个问题,我必须获取代码。有什么方法可以让这个有有效期等吗???