sendgrid-nodejs: Subject not being set if using Dynamic templates
I was trying to add subject for my email with dynamic templates but it is not working. Is this a known bug already? Can you suggest any workarounds for this issue?
template code:
<html>
<head>
<title></title>
</head>
<body>
<p> Hello <span>{{test_name}}!</span></p>
</body>
</html>
send mail function:
const sgMail = require('@sendgrid/mail');
sgMail.setApiKey(settings.sendgrid.api_key);
sgMail.setSubstitutionWrappers('{{', '}}');
const msg = {
to: 'test@email.com',
from: settings.sendgrid.from,
subject: 'Test Subject',
templateId: settings.sendgrid.template_id,
dynamic_template_data: {
test_name: 'Testing Name'
},
};
sgMail.send(msg);
About this issue
- Original URL
- State: closed
- Created 8 years ago
- Reactions: 19
- Comments: 37 (5 by maintainers)
Hello @jlouie,
Does your subject area look something like this in the UI?
With Best Regards,
Elmer
The way it worked for me:
use in subject field in SendGrid UI:
{{{subject}}}send
"subject": "test"inmessage.dynamic_template_dataSuggestion: You guys should really work on your docs. I mean really they are so scattered and bits and pieces are outdated.
The only way I was able to solve this issue was with triple-stash:
{{{ subject }}}According to this article https://github.com/sendgrid/sendgrid-nodejs/blob/master/use-cases/transactional-templates.md
@thinkingserious
Why is this issue closed? It is not fixed.
Hello @nyel-dev,
I believe in the transactional template you would set the subject to be {{ subject }}, then in your code you set
data.subjectto be"[TEST] My Email Subject".Does that work for you?
With Best Regards,
Elmer
November 2021, still not working according to the documents
I suggest that the settings change to the menu like code, test data.
The place where is the settings, is hidden 😕
Hello @jlouie,
Here is a complete example. I hope that helps!
With Best Regards,
Elmer
use in subjects {{subject}}
and send as variable like other variables ,
this way it work .
This worked for me! Your doc should look something like:
Please do re-open issue! The documents still are not correct suggesting
subjectto be set on the top level of the request. However, it must be included indynamic_template_dataand subject in template must be set as{{subject}}or any other dynamic key. This is open from 2018 and no any changes in documentation introduced since!Triple brackets is still working, I’m just checking to see if that is still the official solution.
Thanks!
I notice the subject always use the dynamic template setting from official
message = Mail( from_email=FROM_EMAIL, to_emails=TO_EMAILS, subject='a test subject' )The param “subject” in above code is not workingBy the way I was able to solve this problem by using the Set Subject on the Sendgrid template interface. Thanks @thinkingserious
@thinkingserious the subject not show in email same with example