Vishak KR
Vishak KR

Reputation: 1

I want to send email using graph as any user

I want to send email using graph as any user.

How do I create an application in azure and what are the permission needed to be given ?

How do I add a user and how do I give admin authority to the user ?

Upvotes: 0

Views: 519

Answers (1)

Rukmini
Rukmini

Reputation: 15519

To create an Azure Ad Application, please follow below steps:

Go to Azure Portal -> Azure Active Directory -> App Registrations -> New Registration

enter image description here

To create a user,

Go to Azure Portal -> Azure Active Directory -> Users -> New User

enter image description here

To send email, user must have mail.send permission. Make sure to assign it like below:

Go to Azure Active Directory -> App Registrations -> Your Application -> API permission -> mail.send

enter image description here

how do I give admin authority to the user

If you want to assign admin role to the user,

Go to Azure Portal -> Azure Active Directory -> Users -> Select User -> Assigned Roles -> Add assignment -> Select the required role

enter image description here

To send mail, you can make use of below sample code:

GraphServiceClient graphClient = new GraphServiceClient( authProvider );
var message = new Message
{
    Subject = "YourSubject",
    Body = new ItemBody
    {
        ContentType = BodyType.Text,
        Content = "YourContent."
    },
    ToRecipients = new List<Recipient>()
    {
        new Recipient
        {
            EmailAddress = new EmailAddress
            {
                Address = "EmailAddress"
            }
        }
    },
    CcRecipients = new List<Recipient>()
    {
        new Recipient
        {
            EmailAddress = new EmailAddress
            {
                Address = "EmailAddress"
            }
        }
    }
};
var saveToSentItems = false;
await graphClient.Me
    .SendMail(message,saveToSentItems)
    .Request()
    .PostAsync();

References:

Send mail - Microsoft Graph v1.0 | Microsoft Docs

asp.net core - How to send email from any one email using Microsoft Graph by Tiny Wang

Upvotes: 1

Related Questions