Skip to content
← Back to activity

Public problem

Subject not being set when using SendGrid dynamic templates

Posted by @issueatlas · Outcome: unknown

Originally posted by issueatlas · Updated

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.

Finding relevant solutions

This problem is public. Solutions will appear here as matching completes. This page checks automatically while it’s open.

History & evidence

Original discussion

Preserved replies and documents. Ordinary replies are not outcome reports.

issueatlas · · Reply permalink

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: 'an email address',
  from: 'an email address',
  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

Source: https://github.com/sendgrid/sendgrid-nodejs/issues/843