I'm trying to use a Sendgrid transactional template to send informational emails like account validation etc, using the sendgrid node client. I created one main transactional template which should have a button that has a dynamic body text and a button with a dynamic URL/href attribute for each mail.
My substitution for the button text works, and if I replace it with the URL substitution, I get to see the URL too in text. However, when I try to append the url to the href attribute it disappears, it simply strips the href attribute from my anchor tags. This happens everywhere, whether I'm setting the button url in the visual builder, in an HTML snippet, or in my mail body, it doesn't matter. Setting a URL manually tho, without substitution, seems to work.
I also tried using %value% as substitution, and multiple mail clients (gmail, outlook) but to no avail.. See my function to send informational emails below:
const sendInformationalEmail = async (to, subject, body, substitutions) => {
const fromMail = new helper.Email(SENDGRID_FROM_MAIL);
const toMail = new helper.Email(to);
const content = new helper.Content('text/html', body);
const mail = new helper.Mail(fromMail, subject, toMail, content);
mail.setTemplateId(process.env.SENDGRID_INFORMATIONAL_TEMPLATE_ID);
Object.keys(substitutions).map(substitution => {
mail.personalizations[0].addSubstitution(
new helper.Substitution(`-${substitution}-`, substitutions[substitution])
);
});
const request = sendgrid.emptyRequest({
method: 'POST',
path: '/v3/mail/send',
body: mail.toJSON()
});
return await sendgrid.API(request, function(err, response) {
console.log(response.statusCode);
console.log(response.body);
console.log(response.headers);
});
}