handlebars.js - 用于在 Handlebars 表达式中使用收件人变量批量发送的 Mailgun 模板
问题描述
我正在尝试为批量发送创建 Mailgun 模板,并且该模板需要使用Handlebars条件中的接收者变量来确定要使用的语言,如下所示:
<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 批量发送的文档,因此它可能是不可能的。
有没有人成功地做到这一点?
解决方案
您需要将参与者变量复制为电子邮件的标准变量。请注意以 -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>
推荐阅读
- php - 获取当前用户 WordPress 返回空值
- c# - 日期减法后如何返回很长时间?
- eloqua - 向 Eloqua Marketing Cloud 中的自定义对象中关联多个记录的同一电子邮件地址发送电子邮件
- ionic-framework - Ionic 版本 - 了解 ionic cli 版本和 ionic core 版本之间的区别
- mysql - MySQL:寻求帮助来定义查询
- java - 如何使用原始 SQL 查询在 Moqui 中查找实体?
- c - C 中的 pow 函数未按预期工作
- python - Python中的函数参数转换
- macos - Macos 应用程序在使用 NSDistributedNotificationCenter 和 CFRunLoopAddSource 时挂起
- mysql - Postgres 表大小如何大于 Mysql 表大小?