I am trying to explore the MailGun API for a project at my office and i am stuck with Handlebars and Templates.
I have the following template ("mastertemplate") HTML in MailGun Control Panel
<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
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
a@yopmail.com Hi %recipient.lead_lastname%, %recipient.lead_firstname%
For the 2nd email it should have displayed: Hi Jon Doe
Check your email template - As per the mailgun documentation a conditional looks like the following
{% if is_birthday %}
<p>Happy Birthday! Use the coupon code BIRTHDAY10 to receive 10% off your next order.</p>
{% endif %}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.