【问题标题】:Mailgun batch sending template with recipient variables in Handlebars ExpressionMailgun 批量发送模板与 Handlebars Expression 中的收件人变量
【发布时间】:2020-12-30 07:34:50
【问题描述】:

我正在尝试为我办公室的一个项目探索 MailGun API,但我被 Handlebars 和 Templates 卡住了。

我在 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# 代码

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%

对于第二封电子邮件,它应该显示:Hi Jon Doe

【问题讨论】:

    标签: c# handlebars.js mailgun


    【解决方案1】:

    检查您的电子邮件模板 - 根据the mailgun documentation,条件如下所示

    {% if is_birthday %}
    <p>Happy Birthday! Use the coupon code BIRTHDAY10 to receive 10% off your next order.</p>
    {% endif %}
    

    【讨论】:

    • 这不起作用,因为它使用了 Jinja,它不是 MailGun 的默认模板引擎。默认情况下它使用 Handlebars.js
    猜你喜欢
    • 1970-01-01
    • 2016-10-23
    • 2014-12-15
    • 2017-11-12
    • 2016-07-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-07-30
    相关资源
    最近更新 更多