mailgun-mustache-mailer
v1.0.2
Published
a library for sending mustache formatted mails via mailgun
Downloads
3
Readme
mailgun-mustache-mailer
This is a simple wrapper around mustache and mailgun.com's email API.
It is constructed by supplying the domain and API-key obtained from mailgun.com, as well as the email address that emails should appear to be sent from.
A second argument, log
may is supplied, with a single method info
, which is called when the mailer wants to log something.
It defaults to { info: console.log }
.
var MailgunMustacheMailer = require("mailgun-mustache-mailer");
var config = { domain: "example.com", apiKey: "secret-mailgun-key", from: "[email protected]" };
var mailgunMustacheMailer = new MailgunMustacheMailer(config);
After construction, the object can be used to send either single emails:
var template = {
subject: "Hello {{name}}!",
text: "Hello {{name}}!\n",
html: "<p>Hello {{name}}!</p>"
};
var recipient = {
email: "[email protected]",
name: "Asbjørn Thegler"
};
mailgunMustacheMailer.send(template, recipient, (error, mailId) => {
if(error) return console.log(error);
console.log("New mail was send with id %s", mailId);
});
.. or batch jobs:
var template = {
subject: "Hello {{name}}!",
text: "Hello {{name}}!\n",
html: "<p>Hello {{name}}!</p>"
};
var recipients = [{
email: "[email protected]",
name: "Asbjørn Thegler"
}];
mailgunMustacheMailer.sendBatch(template, recipients, callback);
The callback from the batch job will be passed either an error or a list of objects zipping email addresses with mailId from mailgun.com.