Sendgrid-nodejs: & character escaped to & on dynamic template subjects

Created on 17 Sep 2018  ·  5Comments  ·  Source: sendgrid/sendgrid-nodejs

Issue Summary

When using dyamic templates and substitutions to set the e-mail subject, the character & is escaped to & which makes the subject of the e-mail not show company / product names correctly.

EX: The subject is of the message received is Thanks for buying at C&A instead of the expected: Thanks for buying at C&A.

Steps to Reproduce

  1. Create a new dynamic template and set the subject to {{subject}}

  2. Send the e-mail informing a subject containing the & character:

const sgMail = require("@sendgrid/mail");

const templateId = "XXXXXXXX";
const apiKey =  "XXXXXXXXXX";

sgMail.setApiKey(apiKey);
const msg = {
  templateId,
  to: "[email protected]",
  from: "[email protected]",
  dynamic_template_data: {
    subject: "Escape & work"
  }
};
sgMail.send(msg);
  1. Check your e-mail client for the message with subject Escape & work

Technical details:

  • sendgrid-nodejs Version: 6.3.1
  • Node.js Version: 6.10.3
unknown or a help wanted question

Most helpful comment

Hello @rafaelrpinto

Looks like what you need to do is use a triple bracket on your subject so that handlebars does not HTML encode the content. So instead of using {{subject}} use {{{subject}}}. We have an example of this in our docs here and is talked about in the handlebars documentation here under HTML Escaping.

All 5 comments

Hello @rafaelrpinto

Looks like what you need to do is use a triple bracket on your subject so that handlebars does not HTML encode the content. So instead of using {{subject}} use {{{subject}}}. We have an example of this in our docs here and is talked about in the handlebars documentation here under HTML Escaping.

@kylearoberts

Yep, that solves my problem.

Thanks for the quick response.

Rafael

@kylearoberts

Yep, that solves my problem.

Thanks for the quick response.

Rafael

Please show how your msg looks like (code example) after you added {{{}}} ?

@maxirby

The code is the same, what changed is the subject definition on the template where I set to: {{{subject}}} instead of {{subject}}

Thanks

On Thu, Aug 29, 2019 at 12:11 PM Rafael Pinto notifications@github.com
wrote:

@maxirby https://github.com/maxirby

The code is the same, what changed is the subject definition on the
template where I set to: {{{subject}}} instead of {{subject}}


You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
https://github.com/sendgrid/sendgrid-nodejs/issues/741?email_source=notifications&email_token=AAN3HIAAR4C4A7P5BMV46M3QG6OFDA5CNFSM4FVM6IJ2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOD5N7KTI#issuecomment-526120269,
or mute the thread
https://github.com/notifications/unsubscribe-auth/AAN3HICBW77KL3A637OMKTDQG6OFDANCNFSM4FVM6IJQ
.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

agostonbonomi picture agostonbonomi  ·  3Comments

umarhussain15 picture umarhussain15  ·  3Comments

thinkingserious picture thinkingserious  ·  4Comments

Chrischuck picture Chrischuck  ·  3Comments

nicoasp picture nicoasp  ·  3Comments