Reputation: 111
I'm sending emails using the Sendgrid API, but every email that I send does not have the Subjet
.
My code looks like this:
def send_notification(sendgrid_key, p_email):
message = Mail(
from_email=('[email protected]'),
to_emails=(p_email),
subject='subject email',
)
message.template_id = 'XXXXXX'
try:
sg = SendGridAPIClient(sendgrid_key)
response = sg.send(message)
except Exception as e:
print(str(e))
Eventhought, I have set the subjet
, I'm still receiving emails without subject. Moreover, I do not have any errors when my app run.
Upvotes: 1
Views: 2073
Reputation: 73075
Twilio SendGrid developer evangelist here.
When you are using SendGrid's dynamic templates you actually set the subject in the template, not through the API. Take a look at this screenshot to see where you set the subject in the template editor.
If you want to set the subject dynamically too, you can add a template string in the subject and set that through dynamic template variables when you send the email. Check this article on creating a dynamic email subject line with mustache templates for more information.
Upvotes: 1