How to see mails sent through Microsoft Graph API in Outlook Sent mails folder

120 Views Asked by At

Is it possible to see mails sent through Microsoft Graph API in Outlook Sent mails folder? I thought this was automatic, but apparently when I send an email via Microsoft Graph the address that sent the email does not have the sent message inside the Sent folder.

I don't understand if I have to configure my Tenant in order to do this or it's some kind of configuration that I have to write in the code. I'm using the Microsoft.Graph sdk (4.46.0.0) and sending the email through the SendMail method from the GraphServiceClient.

This is the message object from Microsoft.Graph, the attachments are a MessageAttachmentsCollectionPage object.

var message = new Message
    {
        Subject = "subject",
        Body = new ItemBody
        {
           ContentType = BodyType.Html,
           Content = "bodyhtml"
        },
        Attachments = graphAttachments
    };

Then I just populate the Recipient collections (ToRecipients, CcRecipients and BccRecipients)

recipients.Add(new Recipient
    {
       EmailAddress = new EmailAddress
       {
           Address = m
       }
 });

This is the method I'm using

await _graphServiceClient.Users["[email protected]"]
    .SendMail(message, false)
    .Request()
    .PostAsync();
1

There are 1 best solutions below

0
G. Caldironi On

The error was happening when invoking the client SendMail method, the parameter SaveToSentItems must be true.

await _graphServiceClient.Users["[email protected]"]
    .SendMail(message, true)
    .Request()
    .PostAsync();