0

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 ?

Kiquenet
  • 14,494
  • 35
  • 148
  • 243
  • I think this answer may help you : https://stackoverflow.com/a/70780395/15581227 – Tiny Wang Jul 14 '22 at 06:13
  • 1
    `send email using graph as any user` what does it mean? Does it mean you want users sign in first and send email on behalf of himself? – Tiny Wang Jul 14 '22 at 06:14

1 Answers1

1

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

Rukmini
  • 6,015
  • 2
  • 4
  • 14