如何计算SendGrid中每个个性化块的替换限制?

时间:2018-07-26 06:50:41

标签: sendgrid

我正在尝试使用事务模板通过SendGrid发送电子邮件,并看到替换受限的问题。

  

每个个性化块的替换限制为10000个字节。

SendGrid Docs

我将通过从SendGrid获取模板并替换其中的所有占位符来解决此问题。但是我需要检查什么时候可以做到,我认为将检查有限的替换,并且我不知道SendGrid如何计算它?也许所有字符串的长度都可以替换?

有帮助吗?

谢谢!

2 个答案:

答案 0 :(得分:0)

我解决了我的问题,并与关心的人分享解决方案;)

解决方案:

  

您需要通过将其与Sections一起使用来优化Substitution

    /**
     * When you have the $variables too big, SendGrid will reject the message because
     * SendGrid's Substitution is limited(10000 bytes)
     *
     * Before that, the format of substitution as below:
     *
     * {
     *    "to": [
     *       "example@example.com"
     *    ],
     *    "sub": {
     *       "%FirstName%": "This string maybe too long",
     *       "%LastName%": "This string maybe too long",
     *       ....
     *       ....
     *       more and limited
     *    }
     * }
     *
     * To resolved this problem we will use the Section with Substitution as below:
     *
     * {
     *    "to": [
     *       "example@example.com"
     *    ],
     *    "sub": {
     *       "%FirstName%": "%FirstName%",
     *       "%LastName%": "%LastName%",
     *       ....
     *       ....
     *       more and more
     *    },
     *    "section": {
     *       "%FirstName%": "This string maybe too long",
     *       "%LastName%": "This string maybe too long",
     *       ....
     *       ....
     *     }
     * }
     *
     * We will optimize the strings in Substitutions and let Section in SendGrid to contain that strings.
     */

答案 1 :(得分:0)

根据sendgrid文档,他们将删除对 部分 的支持。正如他们所说,替代是Section的替代选择。对于大内容(> 10000字节),您还有其他选择吗?