Search code examples
node.jscharacter-encodingamazon-ses

InvalidParameterValue: Duplicate header 'Content-Transfer-Encoding'


when I am trying to send an attachment with an email I got this error can anyone tell me what am I doing wrong here is the code which i have tried

var payload = `From: 'Amarjeet Singh' <${sender}>
To: ${recipient}
Subject: AWS SES Attachment
MIME-Version: 1.0
Content-Type: multipart/mixed; boundary=7f1a313ee430f85a8b054f085ae67abd6ee9c52aa8d056e7f7e19c6e2887
--NextPart
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
This is the <b>body</b> of the email.
--7f1a313ee430f85a8b054f085ae67abd6ee9c52aa8d056e7f7e19c6e2887
Content-Type: application/json; charset=UTF-8; 
Content-Disposition: attachment; filename="colors.json"
Content-Transfer-Encoding: base64
${file}
--NextPart--`;

var params = {
    RawMessage: {
      Data: payload
    },
    Source: "xyz@gmail.com"
  };

Solution

  • If you are using AWS SES your payload has two issues, first your boundary is different, and second just keep in mind the line breaks, your string template should be like this:

    var payload = `From: 'Amarjeet Singh' <${sender}>
    To: ${recipient}
    Subject: AWS SES Attachment
    MIME-Version: 1.0
    Content-Type: multipart/mixed; boundary=7f1a313ee430f85a8b054f085ae67abd6ee9c52aa8d056e7f7e19c6e2887
    
    --7f1a313ee430f85a8b054f085ae67abd6ee9c52aa8d056e7f7e19c6e2887
    Content-Type: text/html; charset=UTF-8
    Content-Transfer-Encoding: quoted-printable
    
    This is the <b>body</b> of the email.
    
    --7f1a313ee430f85a8b054f085ae67abd6ee9c52aa8d056e7f7e19c6e2887
    Content-Type: application/json; charset=UTF-8; 
    Content-Disposition: attachment; filename="colors.json"
    Content-Transfer-Encoding: base64
    
    ${file}
    --7f1a313ee430f85a8b054f085ae67abd6ee9c52aa8d056e7f7e19c6e2887--`;