简体   繁体   English

Mailgun 批量发送模板与 Handlebars Expression 中的收件人变量

[英]Mailgun batch sending template with recipient variables in Handlebars Expression

I am trying to explore the MailGun API for a project at my office and i am stuck with Handlebars and Templates.我正在尝试为我办公室的一个项目探索 MailGun API,但我被把手和模板困住了。

I have the following template ("mastertemplate") HTML in MailGun Control Panel我在 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>

Following is the C# Code to send Email以下是 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\"}}"

Now the problem is when emails are received they are like below:现在的问题是收到电子邮件时,它们如下所示:

b@yahoo.com Hi Dong, Van b@yahoo.com你好,范

a@yopmail.com Hi %recipient.lead_lastname%, %recipient.lead_firstname% a@yopmail.com嗨 %recipient.lead_lastname%, %recipient.lead_firstname%

For the 2nd email it should have displayed: Hi Jon Doe对于第二个 email 它应该显示:嗨 Jon Doe

Check your email template - As per the mailgun documentation a conditional looks like the following检查您的 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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM