Skip to content

LobeTia/trailpack-mailgun

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

42 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

Install manually or via generator-trails

$ 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]>",
  // you can use all mailgun-js options
}

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", {username:"Jon", now: new Date()}, {
  to: "[email protected]",
  subject: "HTML hello from trailpack-mailgun"
}).then(app.log.info).catch(app.log.error)

About

Send transactional emails with Mailgun & Trails

Resources

License

Stars

Watchers

Forks

Packages

No packages published