首页 > 解决方案 > 如何计算 SendGrid 中每个个性化块的替换限制?

问题描述

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

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

SendGrid 文档

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

有什么帮助吗?

谢谢!

标签: sendgrid

解决方案


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

解决方案:

您需要通过与 Sections 一起使用来优化 Substitutions

    /**
     * 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.
     */

推荐阅读