【问题标题】:Mailgun template for batch sending with recipient variables in Handlebars expression用于在 Handlebars 表达式中使用收件人变量批量发送的 Mailgun 模板
【发布时间】:2019-07-16 08:52:29
【问题描述】:

我正在尝试为批量发送创建 Mailgun 模板,并且该模板需要在 Handlebars 条件下使用 recipient variable 来确定要使用的语言,例如所以:

<div>
  {{#if %recipient.eng%}}
    Hello
  {{else}}
     Bonjour
  {{/if}}
</div>

但是,在进行 POST 调用以创建上述模板时,我收到错误响应:

 "message": "template parse error: Parse error on line 2:\nLexer error\nToken: Error{\"Unexpected character in expression: '%'\"}"

Mailgun 网站上没有任何使用 Handlebars 批量发送的文档,因此它可能是不可能的。
有没有人成功做到这一点?

【问题讨论】:

  • 你能解决你的问题吗?您使用的替代选项是什么?

标签: handlebars.js mailgun


【解决方案1】:

您需要将参与者变量复制为电子邮件的标准变量。注意以 -F v:eng 开头的行。

curl -s --user 'api:YOUR_API_KEY' \
https://api.mailgun.net/v3/YOUR_DOMAIN_NAME/messages \
-F from='Excited User <YOU@YOUR_DOMAIN_NAME>' \
-F to=alice@example.com \
-F to=bob@example.com \
-F recipient-variables='{"bob@example.com": {"first":"Bob", "id":1, "eng": true}, "alice@example.com": {"first":"Alice", "id": 2, "eng": false}}' \
-F v:eng='%recipient.eng%'
-F subject='Hey, %recipient.first%' \
-F text='If you wish to unsubscribe, click http://mailgun/unsubscribe/%recipient.id%'

然后您将能够使用车把模板中的标准变量访问它

<div>
  {{#if %eng%}}
    Hello
  {{else}}
     Bonjour
  {{/if}}
</div>

【讨论】:

  • 您好,感谢您的建议。但问题在于在模板中使用“带车把”表达式的收件人变量。您的文本中没有车把表达式。 Mailgun 建议这是不可能的。
  • @GlenAu-Yeung 我已经扩展了我的答案以澄清
  • @thelem 我正在尝试使用您的示例,但它不起作用。当我在模板中使用 {{#if %eng%}} 时,它不会在 MailGun 控制面板中更新模板。抛出异常。
  • @Dot_NETPro 这听起来需要一个新问题,包括您在模板中输入的内容的完整详细信息以及引发的异常。
【解决方案2】:

在向 Mailgun 支持人员提出问题后,他们最近回复了我。
结论是不幸的是,在 handlebars 表达式中无法使用 recipient variables .

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-12-15
    • 2016-10-23
    • 2017-11-12
    • 1970-01-01
    • 1970-01-01
    • 2015-09-15
    • 2018-09-05
    • 2019-05-11
    相关资源
    最近更新 更多