有没有办法通过 SendGrid API 调用检索动态模板生成的 HTML 电子邮件正文?

day*_*ker 11 sendgrid sendgrid-api-v3 sendgrid-templates

我们有一个站点,我们的代理输入一些数据,然后该数据通过 SendGrid 动态模板发送到客户端。

电子邮件内容包含大量基于输入数据的计算,因此我们希望我们的代理能够在将其发送给客户之前先预览电子邮件并验证内容。

有没有办法使用 SendGrid API 使用 json 对象发送请求,而不是将电子邮件发送给客户端,而是接收生成的电子邮件正文,以便我们可以将其显示给代理并让他们先查看?

day*_*ker 6

回答了我自己的问题。API v3 具有用于动态事务模板和模板版本的 GET 方法。

API调用:

/templates/{template_id}/versions/{version_id}
Run Code Online (Sandbox Code Playgroud)

使用 sendgrid-ruby:

sg = SendGrid::API.new(api_key: sendgrid_api_key)
sg.client.templates._(template_id).versions._(template_version_id).get
Run Code Online (Sandbox Code Playgroud)

(注:template_version_id是模板版本的ID,不是名称)

然后,响应正文包含一个名为 的字段,html_content该字段是具有任何车把模板的动态模板版本的完整呈现的 HTML。