template html code:
<div style="text-align: center;"><span style="font-size:28px;"><strong><p>Code: {{voucherCode}}</p></strong></span></div>
Nodejs Code:
sgMail.setApiKey(process.env.SENDGRID_API_KEY);
//sgMail.setSubstitutionWrappers('{{', '}}'); // Configure the substitution tag wrappers globally
const msg = {
to: '[email protected]',
from: '[email protected]',
templateId: 'd-787c96877a394be5b95c91750622fed1',
dynamicTemplateData : {
voucherCode: "Some One"
},
};
sgMail.send(msg)
When I received the email, the voucherCode is empty!
I'm having the same issues. I've spent already like 4 hours. What's going on?
I'm seeing some issues with other languages too
@kayson123 I did a last change and it was updating to the last release https://github.com/sendgrid/sendgrid-nodejs/issues/703#issuecomment-411058053
Now is working for me. Try doing that.
Hello @kayson123,
Have you upgraded the SDK to v6.3.1?
Also, you may try {{ voucherCode }}
vs {{voucherCode}}
.
Thanks!
With Best Regards,
Elmer
@juliankmazo,
Thanks for jumping in to help!
It looks like the dynamic_template_data
_must_ be inside a personalizations
array in order for it to work.
This works for me:
from: '[email protected]',
subject: 'Thanks for your recent review',
templateId: 'template_id',
personalizations: [
{
to: {
name: 'Some One',
email: '[email protected]'
},
dynamic_template_data: {
review: {
url: 'https://www.google.com'
}
}
}
]
Above poster is correct. There is a bug either in the library code or typescript definitions.
export interface PersonalizationData {
to: EmailData | EmailData[],
cc?: EmailData | EmailData[],
bcc?: EmailData | EmailData[],
subject?: string;
headers?: { [key: string]: string };
substitutions?: { [key: string]: string };
dynamicTemplateData?: { [key: string]: string; };
customArgs?: { [key: string]: string };
sendAt?: number;
}
This would suggest that you can pass dynamicTemplateData
as a value in PersonalizationData
, but it has to actually be snake case, dynamic_template_data
.
With a fresh install of sendgrid 6.4.0, this issue is still present. The dynamic template data, is only working if passed with dynamic_template_data
, but types suggests dynamicTempalteData.
I'm facing the same issue. Are the typescript definitions for the library incorrect? Can someone please respond.
I spent 2 hours trying to debug this issue only to realize that the issue occurs on a BCC'ed email.
Is there any workaround to this issue? I'm facing the same problem.
@CShigaki Could you provide sample code and template that's not working? And what library version are you using?
@childish-sambino I'm actually using a PHP library and the problem only occurs as @coolnalu said. When setting a BCC through the sendgrid interface (https://app.sendgrid.com/) instead of setting it with code, the email sent to the BCC does not receive (or apply, I don't know yet) the dynamic template data. I have no idea why this happens but I solved it by setting the BCC via code.
Yup, I'm seeing the same issue. The To and Bcc get the email, but the dynamic template is not populated in the Bcc when using the global Bcc account setting. Unfortunately, that's not something that we can resolve in this helper lib so best to create a support ticket to request that this bug be fixed in the backend.
Hello @kayson123,
Thanks for submitting a GitHub issue! We are very sorry that you are running into this problem. In order to better serve you, as this does not present itself as a library specific issue, we would like to ask that you reach out to our support team at https://support.sendgrid.com.
Thank you!
SendGrid DX Team
The solution that worked for me is placing the dynamic_template_data inside the personalization object in the exact way seen below:
"personalizations": [
{
"dynamic_template_data": {
"fullname": "full Name",
"useremail": ":[email protected]",
"userphone": "56456",
"usermsg": "tex fdsfgasdf t"
},
"to": [
{
"email": "[email protected]"
}
],
"cc": [
{
"email": "[email protected]"
}
]
}
]
Most helpful comment
It looks like the
dynamic_template_data
_must_ be inside apersonalizations
array in order for it to work.This works for me: