I am trying to use the templates that I created in Sendgrid. I want to use the template that I created in Sendgrid to send email (with replacement tag replacement).
Here is what I tried -
import sendgrid sg = sendgrid.SendGridClient('<username>', '<password>') message = sendgrid.Mail() message.add_to('<to-email-address>') message.set_subject('My Test Email') message.add_substitution('customer_link', 'http://my-domain.com/customer-id') message.add_filter('templates', 'enable', '1') message.add_filter('templates', 'template_id', '<alphanumeric-template-id>') message.add_from('<from-email-address>') status, msg = sg.send(message)
However, this gives me the error that '{"errors":["Missing email body"],"message":"error"}' . I tried to add the following lines, but still the same error -
message.set_html('') message.set_text('')
So the exact code I use after using set_html is
import sendgrid sg = sendgrid.SendGridClient('<username>', '<password>') message = sendgrid.Mail() message.add_to('<to-email-address>') message.set_subject('My Test Email') message.add_substitution('customer_link', 'http://my-domain.com/customer-id') message.add_filter('templates', 'enable', '1') message.add_filter('templates', 'template_id', '<alphanumeric-template-id>') message.add_from('<from-email-address>') message.set_html('') message.set_text('') status, msg = sg.send(message)
What am I missing here? The python documentation for the library does not seem to contain anything.
Change One of the workarounds I found comes from the answer below. I set message.set_html(' ') and message.set_text(' ') , which basically gives a space bar. This is strange, but works for this case.