Skip to content

ath88/mailgun-mustache-mailer

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

18 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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: "test@example.com" };

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: "asbjoern@deranged.dk",
    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: "asbjoern@deranged.dk",
    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.

About

a library for sending mustache formatted mails via mailgun

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published