Mailgun.js是否提供发送模板的可能性?

iul*_*net 1 email mailing node.js mailgun

因此,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);
});
Run Code Online (Sandbox Code Playgroud)

而且它们还提供了设计和创建电子邮件模板的可能性。有没有办法通过其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);
});
Run Code Online (Sandbox Code Playgroud)

如果没有,您是否可以建议其他提供这种功能的邮件服务?(我跳过了Mandrill,因为它目前显然已停产,尚不清楚何时可以再次使用它)

adn*_*ili 8

是的,您可以,下面是您所用的格式:

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'
};
Run Code Online (Sandbox Code Playgroud)