How to provide list-unsubscribe header using Microsoft Graph sendEmail API

Andrey Smolkov 20 Reputation points
2024-01-23T23:00:59.25+00:00

Hello! I'm using Microsoft Graph API to send email (here example). We need to implement List-unsubscribe (a native unsubscribe option) solution. To do so, we need to provide "List-unsubscribe" header with unsubscribe link. Here examples https://sendgrid.com/en-us/blog/list-unsubscribe How can I provide "List-unsubscribe" header using Microsoft Graph sendEmail API ? thanks, Andrey

const options = {
	authProvider,
};

const client = Client.init(options);

const sendMail = {
  message: {
    subject: '9/9/2018: concert',
    body: {
      contentType: 'HTML',
      content: 'The group represents Nevada.'
    },
    toRecipients: [
      {
        emailAddress: {
          address: '******@contoso.OnMicrosoft.com'
        }
      }
    ],
    internetMessageHeaders: [
      {
        name: 'List-Unsubscribe',
        value: '<unsubscribe-link>'
      },
    ]
  }
};

await client.api('/me/sendMail')
	.post(sendMail);

Microsoft Security | Microsoft Graph
0 comments No comments
{count} votes

Accepted answer
  1. Anonymous
    2024-01-24T08:52:59.89+00:00

    Hi @Andrey Smolkov,

    internetMessageHeaders only supports custom headers starting with x- or X-. If you want to provide List-unsubscribe, you can use the singleValueExtendedProperties property. For example:

    const options = {
    	authProvider,
    };
    
    const client = Client.init(options);
    
    const sendMail = {
      message: {
        subject: '9/9/2018: concert',
        body: {
          contentType: 'HTML',
          content: 'The group represents Nevada.'
        },
        toRecipients: [
          {
            emailAddress: {
              address: '******@contoso.OnMicrosoft.com'
            }
          }
        ],
        singleValueExtendedProperties [
          {
            id: 'String 0x1045',
            value: 'Test Value'
          },
        ],
      }
    };
    
    await client.api('/me/sendMail')
    	.post(sendMail);
    

    For the rest of the code, you can refer to this tutorial: Build TypeScript apps with Microsoft Graph.User's image Hope this helps. If the reply is helpful, please click Accept Answer and kindly upvote it. If you have additional questions about this answer, please click Comment.

    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.