簡體   English   中英

Mailgun 批量發送模板與 Handlebars Expression 中的收件人變量

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM