简体   繁体   English

SendGrid v3 API - 使用具有空/无内容的模板发送邮件

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

I am attempting to send email using SendGrid v3. 我正在尝试使用SendGrid v3发送电子邮件。

I am using the official csharp nuget package: https://github.com/sendgrid/sendgrid-csharp/ 我正在使用官方的csharp nuget包: 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. 简单的替换值,如-firstname-等。

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. 我只希望使用这个模板,并将替换标签替换为我在有效负载中定义的Personalization.SubstututionTags

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'. 文档建议我必须在有效载荷中发送content - 事实上,如果我发送没有任何“内容”的电子邮件,我将收到错误状态代码400

https://sendgrid.com/docs/API_Reference/Web_API_v3/Mail/errors.html#-Content-Errors 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. 您不能在没有content参数的情况下发送电子邮件。 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? 如果我只想使用模板中的content ,我应该在content包含哪些content

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! 提前致谢!

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%> . 将填充模板正文,无论您在<%body%> 的哪个位置,您在API调用content中发送的任何content都将放入模板中

You do have to pass content in the API call, but it can just be "" . 您必须在API调用中传递内容,但它可以只是"" And you do have to put the <%body%> tag in the Template, but it can be commented out: <!-- <%body%> --> . 而且你必须将<%body%>标记放在模板中,但它可以被注释掉: <!-- <%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. 这是SendGrid理解导致此障碍的要求,他们正在努力删除它,但还没有ETA。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM