trailpack-mailgun
v2.1.2
Published
A new Trails.js Application
Downloads
14
Maintainers
Readme
trailpack-mailgun
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
WARNING still work in progress, things can break
Install
$ npm install --save trailpack-mailgun
yo trails:trailpack trailpack-mailgun
Configure
Add Trailpack
// config/main.js
module.exports = {
packs: [
// ... other trailpacks
require('trailpack-mailgun')
]
}
Configure Mailgun
// config/mailgun.js
module.exports = {
apiKey: "key-******",
domain: "sandbox***.mailgun.org",
defaultFrom: "Your name <[email protected]>",
templateRender:
// you can use all mailgun-js options here
}
Usage
Send email via app.services.MailgunService.send
app.services.MailgunService.messagesSend({
from: "Your Email <[email protected]>", // optional if configured in config/mailgun.js
to: "[email protected]",
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()
Utils
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", {}, {
to: "[email protected]"
}).then(app.log.info).catch(app.log.error)