How to save to Sent Items folder when sending an email from a shared mailbox

Ross MacBean 20 Reputation points
2024-08-05T09:58:14.3166667+00:00

We are using the Graph API to read and send mail from a shared mailbox. However when we send an email it is not being saved to the "Sent Items" folder of that shared mailbox. The app authenticates using an Entra Application with the following permissions.
User's image

We are calling the Graph API from a ASP.NET app using the Microsoft.Graph NuGet package Version 5.56.0.

The app authenticates like so:


private async Task<GraphServiceClient> InitGraphServiceClient()
{
    var clientSecret = await GetClientSecret();

    var settings = graphSettings.Value;
    var credential = new ClientSecretCredential(settings.TenantId, settings.ClientId, clientSecret);
    return new GraphServiceClient(credential, ["https://graph.microsoft.com/.default"]);
}

And then uses the following code to send the email:


// ... code above omitted

var fromAddr = "<shared-mailbox-email-address>"; // Injected from configuration in practice
var requestBody = new SendMailPostRequestBody
{
    Message = new Message
    {
        Subject = subject,
        Body = new ItemBody
        {
            ContentType = BodyTypeToGraphApiBodyType(bodyType),
            Content = body,
        },
        ToRecipients = new List<Recipient>
        {
            new()
            {
                EmailAddress = new EmailAddress
                {
                    Address = to,
                },
            },
        },
        Attachments = attachments.Select(
                a => new FileAttachment
                {
                    OdataType = "#microsoft.graph.fileAttachment",
                    ContentBytes = Convert.FromBase64String(a.Base64Content),
                    Name = a.Name,
                    ContentType = a.ContentType,
                } as Microsoft.Graph.Models.Attachment
            )
            .ToList()
    },
    SaveToSentItems = true
};

_logger.LogInformation("Sending email from {From} to {To} with subject {Subject}", fromAddr, to, subject);

var graphServiceClient = await graphServiceClientProvider.GetGraphServiceClientAsync();
await graphServiceClient.Users[fromAddr].SendMail.PostAsync(requestBody);

Everything works great except the sent item is not saved in the Sent Items folder of the shared mailbox. The email is recieved by the recipient just fine, and the "From" address is set to the shared mailbox like expected.

So far I've tried multiple things:

Neither of these things seemed to have any effect so I'm left wondering how to resolve this.

Microsoft Security | Microsoft Graph
Developer technologies | ASP.NET | Other
Developer technologies | C#
0 comments No comments
{count} votes

Accepted answer
  1. Andy David - MVP 157.8K Reputation points MVP Volunteer Moderator
    2024-08-05T10:40:36.97+00:00
    1 person found this answer helpful.

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.