0
votes

I am trying to send an email as a user as according to this documentation. https://docs.microsoft.com/en-us/graph/api/user-sendmail?view=graph-rest-1.0&tabs=csharp

But this line is giving me an exception

await this.graphclient.Users[this.GetSenderId()] .SendMail(message, null) .Request() .PostAsync();

2
Please explain in detail what problem you encountered.Carl Zhao

2 Answers

0
votes

Send mail as a user:

code:

GraphServiceClient graphClient = new GraphServiceClient( authProvider );

var message = new Message
{
    Subject = "Meet for lunch?",
    Body = new ItemBody
    {
        ContentType = BodyType.Text,
        Content = "The new cafeteria is open."
    },
    ToRecipients = new List<Recipient>()
    {
        new Recipient
        {
            EmailAddress = new EmailAddress
            {
                Address = "[email protected]"
            }
        }
    },
    CcRecipients = new List<Recipient>()
    {
        new Recipient
        {
            EmailAddress = new EmailAddress
            {
                Address = "[email protected]"
            }
        }
    }
};

var saveToSentItems = false;

await graphClient.Users["{user-id}"]
    .SendMail(message,saveToSentItems)
    .Request()
    .PostAsync();
0
votes

We realized we do not have outlook 365 subscription on our Azure AD tenant.