mirror of
https://github.com/pacnpal/django-anymail.git
synced 2025-12-20 11:51:05 -05:00
SendGrid: force empty text and html to " " with template_id
Work around an unexpected limitation in SendGrid template rendering, where template text or html bodies are omitted if the supplied message text or html is "". Changing empty string to " " works around the issue. https://sendgrid.com/docs/API_Reference/Web_API_v3/Transactional_Templates/smtpapi.html#-Text-or-HTML-Templates Closes #32
This commit is contained in:
@@ -290,6 +290,12 @@ class SendGridPayload(RequestsPayload):
|
||||
def set_template_id(self, template_id):
|
||||
self.add_filter('templates', 'enable', 1)
|
||||
self.add_filter('templates', 'template_id', template_id)
|
||||
# Must ensure text and html are non-empty, or template parts won't render.
|
||||
# https://sendgrid.com/docs/API_Reference/Web_API_v3/Transactional_Templates/smtpapi.html#-Text-or-HTML-Templates
|
||||
if not self.data.get("text", ""):
|
||||
self.data["text"] = " "
|
||||
if not self.data.get("html", ""):
|
||||
self.data["html"] = " "
|
||||
|
||||
def set_merge_data(self, merge_data):
|
||||
# Becomes smtpapi['sub'] in build_merge_data, after we know recipients and merge_field_format.
|
||||
|
||||
Reference in New Issue
Block a user