【发布时间】:2019-04-11 17:53:56
【问题描述】:
所以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);
});
它们还提供了设计和创建Email Templates 的可能性。有没有办法通过他们的 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,因为它目前显然已经关闭,没有明确估计它何时会再次可用)
【问题讨论】:
标签: node.js email mailgun mailing