sendgridsendgrid-api-v3sendgrid-templates

Warning while sending template email via sendgrid with '&'


I'm sending an email with help of the sendgrid api v3 but got the warning/error:

Content with characters ', " or & may need to be escaped with three brackets {{{ content }}}

in my api json i'm adding an link containing the & character:

{"dynamic_template_data": {"link":"...&..."}}

in my template i'm using the three brackets {{{ link }}}

Everything works as expected - email incl. link are send - but i always got the warning/error.

Do i miss something within the json?


Solution

  • I've looked at their code for node.js and as long as any content string has either a (",',&) it will console.warn the message your are seeing.

    if (/['"&]/.test(value)) {
       console.warn(DYNAMIC_TEMPLATE_CHAR_WARNING);
    }
    

    See: https://github.com/sendgrid/sendgrid-nodejs/blob/47b6a5cd583cc10544ac19434419bdda5272b107/packages/helpers/classes/mail.js

    You can notice the difference with using 2 vs 3 brackets on sendgrid's email template below: enter image description here