Sharepoint - SP.Utilities.Utility.SendEmail with additional headers [javascript]

John is more or less right, but you need to use SP.KeyValue afaik:

'properties': {
               '__metadata': { 'type': 'SP.Utilities.EmailProperties' },
               'From': from,
               'To': { 'results': [to] },
               'Body': body,
               'Subject': subject,

                "AdditionalHeaders":
                {"__metadata":
                    {"type":"Collection(SP.KeyValue)"},
                    "results":
                    [ 
                        {               
                            "__metadata": {
                            "type": 'SP.KeyValue'
                        },
                            "Key": "X-MC-Tags",
                            "Value": 'test',
                            "ValueType": "Edm.String"
                       }
                    ]
                }
           }

enter image description here

SP.Utilities.EmailProperties:

'AdditionalHeaders': { type:'Collection(SP.KeyValue)' },
'BCC': { type:'Collection(Edm.String)' },
'Body': { type:'Edm.String' },
'CC': { type:'Collection(Edm.String)' },
'From': { type:'Edm.String' },
'Subject': { type:'Edm.String' },
'To': { type:'Collection(Edm.String)' }

Here is a function which will convert a regular object to a SP.KeyValue collection:

function objectToSPKeyValueCollection (obj) {
  return {
    __metadata: {
      type: 'Collection(SP.KeyValue)'
    },
    results: Object.keys(obj).map(key => {
      return {
        __metadata: {
          type: 'SP.KeyValue'
        },
        Key: key,
        Value: obj[key],
        ValueType: 'Edm.String'
      }
    })
  }
}

Looking at the example and your error message, I wonder if AdditionalHeaders needs results (similar to To:)

data: JSON.stringify({
    'properties': {
        '__metadata': { 'type': 'SP.Utilities.EmailProperties' },
        'From': from,
        'To': { 'results': [to] },
        'Body': message,
        'Subject': subject,
        'AdditionalHeaders': {
            'results': [
                { 'content-type': 'text/html' }
            ]
        }
    }
}

Tags:

Javascript