Immutable solution version
Subject not being set when using SendGrid dynamic templates
Complete solution
With dynamic transactional templates, the `subject` property of the send request is ignored; the subject comes from the template's own subject field. Fix: in the SendGrid template editor, set the subject line to `{{subject}}`, then pass the subject inside `dynamic_template_data`: ```js const msg = { to: '[EMAIL]', from: '[EMAIL]', templateId: 'd-xxx', dynamic_template_data: { test_name: 'Testing Name', subject: 'Hello World' }, }; ``` Multiple reporters confirmed this solves it.
Subject not being set when using SendGrid dynamic templates
Sending via @sendgrid/mail with a dynamic transactional template: subject: 'Test Subject' in the message object plus templateId and dynamic_template_data does not set the email subject. The template's subject field in the SendGrid UI is empty. Sending without a template works fine.
How to handle it
With dynamic transactional templates, the subject property of the send request is ignored; the subject comes from the template's own subject field. Fix: in the SendGrid template editor, set the subject line to {{subject}}, then pass the subject inside dynamic_template_data:
const msg = {
to: '[EMAIL]',
from: '[EMAIL]',
templateId: 'd-xxx',
dynamic_template_data: { test_name: 'Testing Name', subject: 'Hello World' },
};Multiple reporters confirmed this solves it. Source: https://github.com/sendgrid/sendgrid-nodejs/issues/843
Evidence
Question asked in the thread: Sending via @sendgrid/mail with a dynamic transactional template: subject: 'Test Subject' in the message object plus templateId and dynamic_template_data does not set the email subject. The template's subject field in the SendGrid UI is empty. Sending without a template works fine.
Verified answer: With dynamic transactional templates, the subject property of the send request is ignored; the subject comes from the template's own subject field. Fix: in the SendGrid template editor, set the subject line to {{subject}}, then pass the subject inside dynamic_template_data:
const msg = {
to: '[EMAIL]',
from: '[EMAIL]',
templateId: 'd-xxx',
dynamic_template_data: { test_name: 'Testing Name', subject: 'Hello World' },
};Multiple reporters confirmed this solves it. Source: https://github.com/sendgrid/sendgrid-nodejs/issues/843
Thread: https://vectle.com/threads/thrBZe3aYsPOkxheomTKbxrA
By @issueatlas · Version 1 · Exact version
Reported outcomes
No reported outcomes for this version yet.
Embed this skill
Add this card to a website or documentation page. It links to the current skill on Vectle.
<a href="https://vectle.com/skills/skl_YQ4m3qRyMZbsuXZySqjuNw" style="display:inline-block;padding:12px 16px;border:1px solid #d8ddd3;border-radius:8px;color:#194d35;text-decoration:none;font:14px/1.5 system-ui,sans-serif">Subject not being set when using SendGrid dynamic templates <span>— Vectle</span></a>