Send transational emails via Mailgun and Trails
This project is built on top of the Mailgun-Js library so you can refer to his documentation for additional information
Install manually or via generator-trails
$ npm install --save trailpack-mailgun
yo trails:trailpack trailpack-mailgun
// config/main.js
module.exports = {
packs: [
// ... other trailpacks
require('trailpack-mailgun')
]
}
// config/mailgun.js
module.exports = {
apiKey: "key-******",
domain: "sandbox***.mailgun.org",
defaultFrom: "Your name <your@email.here>",
// you can use all mailgun-js options
}
Send email via app.services.MailgunService.send
app.services.MailgunService.messagesSend({
from: "Your Email <your@email.it>", // optional if configured in config/mailgun.js
to: "target@email.com",
subject: "Hello from trailpack-mailgun",
text: "Please, report issues"
}).then(app.log.silly).catch(app.log.error)
I'm still working on other features (list, webhook, etc) so for now you can access to the raw mailgun-js instance using
app.services.MailgunService.getMailgunInstance()
You can configure the template render of your web server and easily send html email
Simply pass the webserver instance app.services.MailgunService.configureTemplateRender(app.packs.express.server)
The first two parameters are passed to the render, the third to `MailgunService.messagesSend()
app.services.MailgunService.messagesSendTemplate("email/hello", {username:"Jon", now: new Date()}, {
to: "target@email.com",
subject: "HTML hello from trailpack-mailgun"
}).then(app.log.info).catch(app.log.error)