An API that connects multiple Microsoft services, enabling data access and automation across platforms
Hi @lakshmi
I have been using this code for a long time before I provide you with it and it works fine for me and I can use it to send emails on behalf of any user in my organization.
I noticed you mentioned in your question that you were getting an insufficient permissions error, so have you tried exporting your access token and decoding it to check if it contains the target permissions?
var scopes = new[] { "https://graph.microsoft.com/.default" };
var tenantId = "xxxxxxxxxxxxxxxxxx";
var clientId = "xxxxxxxxxxxxxxxxxxxxxx";
var clientSecret = "xxxxxxxxxxxxxxxxxxxxxxx";
// using Azure.Identity;
var options = new TokenCredentialOptions
{
AuthorityHost = AzureAuthorityHosts.AzurePublicCloud
};
// https://learn.microsoft.com/dotnet/api/azure.identity.clientsecretcredential
var clientSecretCredential = new ClientSecretCredential(
tenantId, clientId, clientSecret, options);
var token = await clientSecretCredential.GetTokenAsync(new TokenRequestContext(scopes));
Console.WriteLine($"Access token: {token.Token}");
Hope this helps.
If the reply is helpful, please click Accept Answer and kindly upvote it. If you have additional questions about this answer, please click Comment.