Last active
May 9, 2020 17:32
-
-
Save SamWSoftware/54d254c9af6840f28e3859ac40636c93 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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