#c# #handlebars.js #mailgun
#c# #handlebars.js #mailgun
Вопрос:
Я пытаюсь изучить API MailGun для проекта в моем офисе, и я застрял с Handlebars и шаблонами.
У меня есть следующий шаблон («mastertemplate») HTML в панели управления MailGun
<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%
Для 2-го электронного письма должно было отображаться: Привет, Джон Доу