You can use the Exchange powershell to set this as what you are looking for is not avail in Graph:
How to save to Sent Items folder when sending an email from a shared mailbox
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.
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:
- Including the 'From' and/or 'Sender' properties in the request body
- Removing the 'SaveToSentItems = true' based on this documentation found here https://learn.microsoft.com/en-us/graph/api/user-sendmail?view=graph-rest-1.0&tabs=http#request-body
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#
-
Andy David - MVP 157.8K Reputation points MVP Volunteer Moderator
2024-08-05T10:40:36.97+00:00