[英]Mailgun batch sending template with recipient variables in Handlebars Expression
我正在尝试为我办公室的一个项目探索 MailGun API,但我被把手和模板困住了。
我在 MailGun 控制面板中有以下模板(“mastertemplate”)HTML
<p style="font-family: Open Sans, sans-serif; font-size: 16px;">
{{#if Islead}}
<p style="box-sizing: border-box;">Hi %recipient.lead_lastname%, %recipient.lead_firstname%</p>
{{else if Iscontact}}
<p style="box-sizing: border-box;">Hi %recipient.contact_lastname%, %recipient.contact_firstname%</p>
{{/if}}
</p>
以下是 C# 代码发送 Email
RestRequest request = new RestRequest();
Dictionary<string, Dictionary<string, object>> recipientvariables = new Dictionary<string, Dictionary<string, object>>();
request.AddParameter("domain", MAILGUN_DOMAIN, ParameterType.UrlSegment);
request.Resource = "{domain}/messages";
request.AddParameter("from", "from@email.com");
request.AddParameter("to", "a@yopmail.com");
request.AddParameter("to", "b@yahoo.com");
request.AddParameter("subject","MailGun Variables Testing");
request.AddParameter("template", "mastertemplate");
request.AddParameter("h:X-Mailgun-Variables", "{\"Iscontact\": \"%recipient.Iscontact%\", \"Islead\": \"%recipient.Islead%\"}");
request.AddParameter("recipient-variables","{\"a@yopmail.com\":{\"contact_firstname\":\"Jon\",\"contact_lastname\":\"Doe\",\"Iscontact\":\"true\",\"Islead\":\"false\"},\"b@yahoo.com\":{\"lead_firstname\":\"Van\",\"lead_lastname\":\"Dong\",\"Iscontact\":\"false\",\"Islead\":\"true\"}}"
现在的问题是收到电子邮件时,它们如下所示:
b@yahoo.com你好,范
a@yopmail.com嗨 %recipient.lead_lastname%, %recipient.lead_firstname%
对于第二个 email 它应该显示:嗨 Jon Doe
检查您的 email 模板 - 根据mailgun 文档,条件如下所示
{% if is_birthday %}
<p>Happy Birthday! Use the coupon code BIRTHDAY10 to receive 10% off your next order.</p>
{% endif %}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.