在节点服务器的 Mailgun 模板中使用变量
Using variables in Mailgun Templates in Node server
我正在尝试创建一个基本的快速路由来处理我的电子邮件模板,但出于某种原因,我无法将变量名称传递到 mailgun。我在别处查过,并尝试以各种可能的方式将变量输入到数据中,无论如何,当收到电子邮件时,变量完全是空白的。还有其他方法可以让我在 api 请求中输入变量吗?
正在发送快递数据:
const data = {
from: "Me <email@gmail.com>",
to: "myEmail@live.com",
subject: "Hello",
template: "thank_you_email",
recipient_name: "My Name",
"v:recipient_name": "My Name",
"h:X-Mailgun-Variables": JSON.stringify({
recipient_name: "My Name",
}),
};
正如您在这段代码中看到的,我尝试以三种不同的方式发送变量,但它似乎没有被发送,尽管主题确实有效。
这是带有此变量的 html 模板部分:
<h3
style="
margin: 0;
line-height: 24px;
mso-line-height-rule: exactly;
font-family: georgia, times,
'times new roman', serif;
font-size: 20px;
font-style: normal;
font-weight: normal;
color: #24578e;
"
>
Dear %recipient_name%,
</h3>
这里有我遗漏的东西吗?谢谢
所以,我在发布这个问题后很快就找到了答案,但我不会删除它,以防其他人遇到问题。在电子邮件模板中,您必须将变量放入 as
{{recipient_name}}
而不是
%recipient_name%
这似乎更有效;唯一的例外是添加取消订阅按钮时,您输入
%unsubscribe_url%
mailgun 会为您处理剩下的事情。
我正在尝试创建一个基本的快速路由来处理我的电子邮件模板,但出于某种原因,我无法将变量名称传递到 mailgun。我在别处查过,并尝试以各种可能的方式将变量输入到数据中,无论如何,当收到电子邮件时,变量完全是空白的。还有其他方法可以让我在 api 请求中输入变量吗?
正在发送快递数据:
const data = {
from: "Me <email@gmail.com>",
to: "myEmail@live.com",
subject: "Hello",
template: "thank_you_email",
recipient_name: "My Name",
"v:recipient_name": "My Name",
"h:X-Mailgun-Variables": JSON.stringify({
recipient_name: "My Name",
}),
};
正如您在这段代码中看到的,我尝试以三种不同的方式发送变量,但它似乎没有被发送,尽管主题确实有效。
这是带有此变量的 html 模板部分:
<h3
style="
margin: 0;
line-height: 24px;
mso-line-height-rule: exactly;
font-family: georgia, times,
'times new roman', serif;
font-size: 20px;
font-style: normal;
font-weight: normal;
color: #24578e;
"
>
Dear %recipient_name%,
</h3>
这里有我遗漏的东西吗?谢谢
所以,我在发布这个问题后很快就找到了答案,但我不会删除它,以防其他人遇到问题。在电子邮件模板中,您必须将变量放入 as
{{recipient_name}}
而不是
%recipient_name%
这似乎更有效;唯一的例外是添加取消订阅按钮时,您输入
%unsubscribe_url%
mailgun 会为您处理剩下的事情。