Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SendGrid v3 API - Send Mail Using Template with Empty/No Content

Tags:

c#

.net

sendgrid

I am attempting to send email using SendGrid v3.

I am using the official csharp nuget package: https://github.com/sendgrid/sendgrid-csharp/

I wish to use a Transactional Template in which I have a series of Substitution Tags defined. Simple substitution values like -firstname- etc.

The Transactional Template that I defined basically has ALL of the required information/content/body defined it already. I only wish to use this template and have the substitution tags replaced with the Personalization.SubstututionTags that I define in the payload.

The documentation suggests that I MUST send content in the payload - in fact it is documented that I will receive an Error Status Code of 400 if I send an email without any 'content'.

https://sendgrid.com/docs/API_Reference/Web_API_v3/Mail/errors.html#-Content-Errors

The content param is required. You may not send an email without the content parameter. This is to prevent you from sending an empty email to your recipients.

What should I include in the content if I simply want the content from the template to be used?

If I include some arbitrary content such as

      'content': [
        {
          'type': 'text/html',
          'value': 'I\'m replacing the <strong>body tag</strong>'
        }
      ],

Won't it overwrite the content from the template with that?

Thanks in Advance!

like image 416
Aaron Glover Avatar asked Nov 09 '22 06:11

Aaron Glover


1 Answers

It's the other way around. The Template body will be populated, and whatever you send in the content of the API call will be put in the Template wherever you have <%body%>.

You do have to pass content in the API call, but it can just be "". And you do have to put the <%body%> tag in the Template, but it can be commented out: <!-- <%body%> -->.

This is a requirement that SendGrid understands causes this hurdle, and they're working on removing it, but don't have an ETA yet.

like image 128
jacobmovingfwd Avatar answered Nov 14 '22 20:11

jacobmovingfwd