To include List-Unsubscribe
mail header, you need to add it via SingleValueExtendedProperties
using Microsoft.Graph.Me.SendMail;
using Microsoft.Graph.Models;
var requestBody = new SendMailPostRequestBody
{
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 = "johndoe@contoso.com",
},
},
},
SingleValueExtendedProperties = new List<SingleValueLegacyExtendedProperty>
{
new SingleValueLegacyExtendedProperty
{
Id = "String 0x1045",
Value = "<mailto:unsubscribe@reply.contoso.com>, <https://contoso.com/notifications/unsubscribe/123>",
},
},
},
};
If you need to include also List-Unsubscribe-Post
, the solution is more complicated, because there is no way to add List-Unsubscribe-Post
via SingleValueExtendedProperties
. You need to send message in MIME format.
Great blog post how to create a MIME message for Graph API is here