2

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();
3
  • Can you provide a part of the code for email sending? Have you tried to utilize the parameter SaveToSentItems? Commented Jul 31, 2023 at 12:09
  • @qwermike I added the code to create the Message object and send the email through the Graph client, the Message class has a lot of properties but none called SaveToSentItems, is it something to write inside the AdditionalData property or something like that? EDIT: Well I answered myself, that false is wrong Commented Jul 31, 2023 at 12:53
  • @qwermike yes it's working, thanks a lot for pointing out the name of the parameter! Commented Jul 31, 2023 at 12:57

1 Answer 1

1

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();
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.