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:
medmunds
2016-10-13 15:15:37 -07:00
parent 771ed513b2
commit a1380b82f3
3 changed files with 27 additions and 0 deletions

View File

@@ -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.