Fastify nodemailer plugin
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
.gitignore
.travis.yml
LICENSE
README.md
example.js
index.js
package.json
test.js

README.md

fastify-nodemailer

js-standard-style Build Status Greenkeeper badge Known Vulnerabilities Coverage Status npm npm

Fastify nodemailer plugin, with this you can share the same nodemailer transporter in every part of your server.

Under the hood the it wraps nodemailer transporter and the options that you pass to register will be passed to the transporter. For configuration/usage details please check the nodemailer documentation.

Install

npm i fastify-nodemailer --save

Usage

Add it to you project with register and you are done! You can access the transporter via fastify.nodemailer and sendMail() via fastify.nodemailer.sendMail().

const fastify = require('fastify')()

fastify.register(require('fastify-nodemailer'), {
  pool: true,
  host: 'smtp.example.com',
  port: 465,
  secure: true, // use TLS
  auth: {
      user: 'username',
      pass: 'password'
  }
})

fastify.get('/sendmail/:email', (req, reply, next) => {
  let { nodemailer } = fastify
  let recipient = req.params.email

  fastify.nodemailer.sendMail({
    from: 'sender@example.com',
    to: recipient,
    subject: 'foo',
    text: 'bar'
  }, (err, info) => {
    if (err) next(err)
    reply.send({
      messageId: info.messageId
    })
  })
})

fastify.listen(3000, err => {
  if (err) throw err
  console.log(`server listening on ${fastify.server.address().port}`)
})

License

Licensed under MIT.