node.js - Node.js 使用模板发送 Mailgun 邮件失败,错误:无法解码变量
问题描述
我第一次尝试在我的后端服务器中发送邮件。到目前为止,我正在探索 Mailgun,我成功地发送了包含一些可变细节的基本文本邮件。我现在正在尝试使用我在 Mailgun 中制作的模板,在该模板中我还使用了传递的变量。
当邮件被发送时,我可以看到 Mailgun 中的状态为失败,并带有传递消息:Failed to decode variables
我看不出我做错了什么
这些是创建的模板邮件期望获得的变量:
{
"clientFirstname": "test_clientFirstname",
"serviceName": "test_serviceName",
"date": "test_date",
"start": "test_start",
"end": "test_end"
}
邮寄功能
function sendMail(emailStatus, client, service , args ){
const DOMAIN = 'dummy_domain';
const api_key ='dummy_apikey';
const mg = mailgun({apiKey: api_key, domain: DOMAIN});
const date = moment(args.start).format('dddd, MMMM Do YYYY ');
const start = moment(args.start).format('HH:mm');
const end = moment(args.end).format('HH:mm');
var data = {};
switch (emailStatus) {
case "create_appointment":
data = {
from: 'Afsprakenbeheer <dummy_mail>',
to: 'dummy_mail',
subject: 'Confirmation appointment',
template: "create-appointment",
h:X-Mailgun-Variables: '{"clientFirstname": "test_clientFirstname", "serviceName":
"test_serviceName","date": "test_date","start": "test_start", "end": "test_end"}'
};
break;
case "update_appointment":
data = {};
break;
case "cancel_appointment":
data = {};
break;
default:
break;
}
mg.messages().send(data, function (error, body) {
console.log(body);
});
}
谁能帮我解决这个问题?
解决方案
我通过这篇文章的答案找到了我的问题的答案 -->使用 Python 通过 Mailgun 提交变量时出错
推荐阅读
- java - 如何将我的源代码更改为可以使用 java 编程语言安装在 Windows 或其他 OS 系统中的真实应用程序?
- css - 如何将 SVG 中的所有路径移动到同一点
- php - SQLSTATE[HY000] [2002] 访问远程数据库时连接超时,日志显示已尝试连接
- django - python文件中html内的django csrf_token
- sql - 错误:在 Spark 中使用 sql 时,GROUP BY 位置 0 不在选择列表中
- node.js - 如何仅为提供的键更新猫鼬文档的嵌套对象
- javascript - 如何使用Javascript / Jquery检测水平滚动的底部视口滚动条
- mysql - SpringBoot Cloud Foundry 覆盖数据库池大小 - 通信链路故障
- c++ - 从特定代码部分跳转到函数开始
- blockchain - Msg.sender 在“视图”函数中不起作用,为什么?有解决方法吗?