Skip to content

Instantly share code, notes, and snippets.

@SamWSoftware
Last active May 9, 2020 17:32
Show Gist options
  • Save SamWSoftware/54d254c9af6840f28e3859ac40636c93 to your computer and use it in GitHub Desktop.
Save SamWSoftware/54d254c9af6840f28e3859ac40636c93 to your computer and use it in GitHub Desktop.
const keys = require("../config/keys");
var domain = keys.mailgunDomain;
var mailgun = require("mailgun-js")({
apiKey: keys.mailgunKey,
domain: domain
});
class MailgunMailer {
constructor({ subject, recipients }, content) {
this.data = {
from: "no-reply@YOUR_ADDRESS.com",
to: this.formatAddresses(recipients),
subject: subject,
html: content
};
}
formatAdresses(recipients) {
return recipients.map(({ email }) => email).join(",");
}
async send() {
const resp = await mailgun.messages().send(this.data);
return resp;
}
}
module.exports = MailgunMailer;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment