Mandrill可编辑模板:mc:edit link href [英] Mandrill Editable Template: mc:edit link href
问题描述
我正在尝试使用Mandrill模板发送订单跟踪电子邮件。
I'm trying to use Mandrill templates to send order tracking emails.
使用mc:edit可以很好地适用于< ; span mc:edit =ship_id> ship_id< / span>< br>
Using the mc:edit works well for simple text like <span mc:edit="ship_id">ship_id</span><br>
我想知道是否有方法将href链接传递给一个变量,即 tracking_url
I was wondering if there was a way to pass the href link in a variable i.e. tracking_url
< a class =mcnButtontitle =Track订单href = tracking_url target =_ blankstyle =font-weight:bold; text-align:center;>追踪顺序< / a>
我在Django中使用Djrill,这里是到目前为止发送电子邮件的代码,我想添加tracking_url作为template_content变量或类似的东西
I'm using Djrill for Django and here's the code which sends the email so far, and I'd like to add tracking_url as a template_content variable or something similar
msg = EmailMessage(subject="Track your order", from_email="admin@example.com", to=[user.email])
msg.template_name = "order-sent"
msg.template_content = {'order_id' : order_id, 'order_date' : order_date, 'order_type' : order_type, 'first_name' : user.first_name, 'last_name' : user.last_name, 'phone' : user.info.phone,
'd_street' : d.street, 'd_zipcode' : d.zipcode, 'd_city' : d.city, 'd_country' : d.country}
msg.send()
它似乎可以使用AddGlobalVariable方法(请参阅 here ),但我无法弄清楚如何使用它..
It seems possible using the AddGlobalVariable method (read here) but I can't figure out how to use it..
推荐答案
我有一个电子邮件调度程序,使用MandripApp发送普通电子邮件(作为SMTP)以及使用模板发送电子邮件。
I have an Email Dispatcher that uses MandripApp to send normal emails (as SMTP) as well to send emails using the template.
我不知道如何传递您要求的内容,因为我没有使用 mc:edit
属性(因为我的用户永远不会自己编辑模板,我或开发人员),但我可以为您提供全局变量的帮助。
I do not know how to pass what you are asking, as I'm not using mc:edit
attributes any longer (as my users will never edit the template themselves, me or a developer will) but I can provide you help with the global variables.
全局变量与Mailchimp vars相同,如 * | EMAIL | *
这是我做的:
Global variables are the same as Mailchimp vars, like *|EMAIL|*
and this is what I do:
var mergeVars = Dictionary<string, string>();
mergeVars.Add("ORDER_ID", orderId);
mergeVars.Add("CUSTOMER_NAME", fullname);
mergeVars.Add("CUSTOMER_FNAME", fullname.Contains(" ") ? fullname.Split(' ')[0] : fullname);
mergeVars.Add("CUSTOMER_EMAIL", email);
例如,一个孔表:
StringBuilder sb = new StringBuilder();
foreach (ProductInfo pi in products)
{
sb.Append("<tr>");
sb.AppendFormat("<td style=\"text-align:left;\"><img src=\"http://dynassets1.gavekortet.dk/{2}/products/trans/{1}_1.png\" alt=\"{0}\" /></td>", pi.Title, pi.ID, shopId);
sb.AppendFormat("<td style=\"text-align:left;\">{0} x {1}</td>", pi.Qty, pi.Title);
sb.AppendFormat("<td style=\"text-align:right;\">{0:N2}</td>", double.Parse(pi.CardValue));
sb.Append("</tr>");
}
mergeVars.Add("ITEMS_LIST", sb.ToString());
我只需要(表格部分):
in my template in MandrillApp I simply have (for the table part):
<table style="width: 100%; padding: 0 30px;">
<thead>
<tr>
<th style="width:75px; text-align:left;">Gavekort</th>
<th style="width:75px; text-align:left;">Ordreoversigt</th>
<th style="width:75px; text-align:right;">Værdi (kr.)</th>
</tr>
</thead>
<tbody>
*|ITEMS_LIST|*
</tbody>
</table>
和您执行的代码:
var tmplMessage = new MandrillSendTemplateItem();
tmplMessage.key = password;
tmplMessage.message = new MessageItem();
// Email Destination
tmplMessage.message.to = new List<MessageToItem>();
tmplMessage.message.to.Add(new MessageToItem() { name = destinationName, email = destinationEmail, type = "to" });
tmplMessage.message.to.Add(new MessageToItem() { name = "Bruno Alexandre", email = "my_email@domain.com", type = "bcc" }); // always send me a copy so I know what's going on
// Global Variables
tmplMessage.message.global_merge_vars = new List<TemplateContentItem>();
tmplMessage.message.global_merge_vars.Add(
new TemplateContentItem() {
name = "TASKCOMPLETE",
content = DateTime.UtcNow.ToString("dd MMM yyyy HH:mm") });
// Global Variables passed in properties
if (properties != null)
{
foreach (var p in properties)
{
tmplMessage.message.global_merge_vars.Add(
new TemplateContentItem() { name = p.Key, content = p.Value });
}
}
并发送电子邮件。
我希望它可以帮助你做你所需要的。
I hope it helps you doing what you need.
注意,您只传递代码中全局变量的名称,但在模板中,您需要调用它,使用 | *
和 * |
so:
Note that you only pass the name of the global variable in your code, but in the template you need to call it wrapping it with |*
and *|
so:
tmplMessage.message.global_merge_vars.Add(
new TemplateContentItem() {
name = "TASKCOMPLETE",
content = DateTime.UtcNow.ToString("dd MMM yyyy HH:mm") });
可在模板中访问:
<span class="completed">*|TASKCOMPLETE|*</span>
这篇关于Mandrill可编辑模板:mc:edit link href的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!