所以MailGun提供了通过他们的节点库发送电子邮件的可能性,实现了他们的API:
var mailgun = require('mailgun-js')({ apiKey: api_key, domain: DOMAIN });
var filepath = path.join(__dirname, 'sample.jpg');
var data = {
from: 'Excited User <[email protected]>',
to: '[email protected], [email protected], [email protected]',
cc: '[email protected]',
bcc: '[email protected]',
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 <[email protected]>',
to: '[email protected], [email protected], [email protected]',
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 <[email protected]>',
to: '[email protected], [email protected], [email protected]',
template: "withdraw_request_approved", //Instead of 'html'
'v:firstName': 'John',
'v:lastName': 'Doe'
};