node.js - Mailgun.js 是否提供发送模板的可能性?
问题描述
因此MailGun提供了通过实现其API的 Node 库发送电子邮件的可能性:
var mailgun = require('mailgun-js')({ apiKey: api_key, domain: DOMAIN });
var filepath = path.join(__dirname, 'sample.jpg');
var data = {
from: 'Excited User <me@samples.mailgun.org>',
to: 'foo@example.com, baz@example.com, bar@example.com',
cc: 'baz@example.com',
bcc: 'bar@example.com',
subject: 'Complex',
text: 'Testing some Mailgun awesomness!',
html: "<html>HTML version of the body</html>",
attachment: filepath
};
mailgun.messages().send(data, function (error, body) {
console.log(body);
});
它们还提供了设计和创建电子邮件模板的可能性。有没有办法通过他们的 API 发送带有一些自定义变量的模板化电子邮件?就像是:
var data = {
from: 'Excited User <me@samples.mailgun.org>',
to: 'foo@example.com, baz@example.com, bar@example.com',
template: "withdraw_request_approved", //Instead of 'html'
vars: { firstName: 'John', lastName: 'Doe' }
};
mailgun.messages().send(data, function (error, body) {
console.log(body);
});
如果没有,您能否推荐一些其他提供这种功能的邮件服务?(我已经跳过了Mandrill,因为它显然目前已经关闭,没有明确估计它何时会再次可用)
解决方案
是的,您可以,以下是您的情况的格式:
var data = {
from: 'Excited User <me@samples.mailgun.org>',
to: 'foo@example.com, baz@example.com, bar@example.com',
template: "withdraw_request_approved", //Instead of 'html'
'v:firstName': 'John',
'v:lastName': 'Doe'
};
推荐阅读
- git - 从克隆的存储库本地恢复提交/在特定提交后重置所有更改
- intellij-idea - 取消注释已注释块内的较小块
- ios - 如何在 Swift 中解析特定的 JSON
- java - 在 Spring Integration 中将“application.errorChannel”添加到配置中
- c++ - Qt 5.11.2(Clang 8.0 (Apple),64 位),未找到 QJSEngine 文件
- unix - Unix awk - 每个唯一值的出现次数
- docker - 将 docker cli bash 命令转换为 api 以供外部应用程序在生产中使用的最安全方法
- mongoose - 猫鼬响应的对象属性未定义
- c - 未定义对函数文件错误 C 的引用(编译)
- c - 为什么空闲 CPU 没有分配给 linux 中的进程?