9

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?

andre_hold
  • 562
  • 8
  • 20

2 Answers2

6

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

Jonathan002
  • 9,639
  • 8
  • 37
  • 58
  • 7
    Is there a way to turn off this warning, it's very annoying when viewing lots of SendGrid email sends. – Luke Brown Dec 20 '19 at 14:31
  • 2
    did you found the way to disable this warning? I'm using `@sendgrid/mail": "^7.2.5` and the warning is still there – Kostanos Sep 16 '20 at 14:40
  • 3
    Looks like the only suggestion is to hide all warnings, which i don't think is a good idea: https://github.com/sendgrid/sendgrid-nodejs/blob/main/docs/use-cases/hide-warnings.md – NaturalDevCR Jan 21 '21 at 15:23
  • @NaturalDevCR yes, hiding all warnings doesn't feel like a good idea. But I checked the code and it looks like this is the only warning _so far_ that can be disabled by that flag. I suggest to hide this warning on specific environments only and still show them in dev and test environments. – Matthias Lohscheidt Jan 31 '23 at 13:43
1

You can disable warnings setting hideWarnings only in you json message not globally:

const msg = {
  to: 'recipient@example.org',
  from: 'sender@example.org',
  templateId: 'd-f43daeeaef504760851f727007e0b5d0',
  dynamic_template_data: {
    link: '...&...',
  },
  hideWarnings: true, // now the warning won't be logged
};
Álvaro Agüero
  • 4,494
  • 1
  • 42
  • 39