【发布时间】:2021-05-28 00:41:56
【问题描述】:
我正在尝试将一些图像 URL 发送到 Mailgun API 以使用我的 Mailgun 电子邮件模板变量。但我无法弄清楚如何通过。我可以使用 v: 传递单个变量,但不知道如何传递数组。我曾尝试将 javascript 对象传递给 Http post 方法,但 Mailgun API 给出“from parameter is missing”错误。
using this way I am able to send data to mailgun api without any issues but don't know how to send array or json object.
var body =
"from=Admin <order@xyz.com>" +
"&to=" + recipient +
"&subject=Order Placed #" + subject +
"&template=my-template" +
"&v:orderID=" + subject +
"&v:userEmail=" + JSON.parse(address).email +
"&v:orderCharges=" + this.price * quantity +
"&v:frameQuantity=" + quantity +
"&v:orderShipping=" + JSON.parse(address).addr +
"&v:orderImage[]=" + encodeURI (message[0]) + "," + encodeURI(message[1]);
var url = "https://api.mailgun.net/v3/" + this.mailgunUrl + "/messages";
this.http.post(url,body,
{
headers: { 'Authorization': 'Basic ' + this.mailgunApiKey, "Content-Type": "application/x-www-form-urlencoded" },
}).subscribe(res => {
console.log('THIS IS EMAIL RES', res);
})
}
当我尝试传递这样的对象时:
{
"from":"order@xyz.com",
"to": "xxxxx@gmail.com",
"subject": "Order Placed #46",
"template": "my-template",
"v:orderID": 46
}
Mailgun API 给我错误“缺少来自参数的错误。我也尝试过 from:order@xyz.com。甚至尝试在 url 后传递 json 对象以发布但仍然是相同的错误。
我已经设法通过构造如上所示的正文将数据发送到 mailgun api,但现在我不知道如何传递数组,因为我不知道用户会选择多少张图片。所以我希望 Handlebars.js 每个循环都使用一个数组来将变量转换为数据。
【问题讨论】:
-
我已按照本指南中的教程将 mailgun 集成到 ionic 中:thepolyglotdeveloper.com/2016/04/…
标签: arrays json angularjs ionic-framework mailgun