All Projects → lependu → fastify-nodemailer

lependu / fastify-nodemailer

Licence: MIT license
Fastify nodemailer plugin

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to fastify-nodemailer

fastify-angular-universal
Angular Universal integration to Fastify for rendering Angular apps on the server
Stars: ✭ 20 (-13.04%)
Mutual labels:  fastify, fastifyjs-plugin
fastify-jwt-authz
Verify authenticated user scope
Stars: ✭ 14 (-39.13%)
Mutual labels:  fastify, fastifyjs-plugin
fastify-file-upload
Fastify plugin for uploading files
Stars: ✭ 68 (+195.65%)
Mutual labels:  fastify, fastifyjs-plugin
fastify-vue
A nuxt.js fastify plugin
Stars: ✭ 27 (+17.39%)
Mutual labels:  fastify
fastify-loader
The route loader for the cool kids!
Stars: ✭ 17 (-26.09%)
Mutual labels:  fastify
pothole detection
By using this app users can report the potholes on road by clicking a photo via our app and if a pothole is detected by Machine Learning modal then it is saved to our Database from where officials can view the specifics like location,reported by and official can resolve the request.User are notified by email for every update regarding their request
Stars: ✭ 17 (-26.09%)
Mutual labels:  nodemailer
zoia2 old
Zoia CMS
Stars: ✭ 24 (+4.35%)
Mutual labels:  fastify
svelte-ssr-example
Svelte SSR example
Stars: ✭ 43 (+86.96%)
Mutual labels:  fastify
fastify-vite
This plugin lets you load a Vite client application and set it up for Server-Side Rendering (SSR) with Fastify.
Stars: ✭ 497 (+2060.87%)
Mutual labels:  fastify
fastify-graphql-nexus-prisma
GraphQL Server with Fastify, Mercurius, Prisma, and Nexus
Stars: ✭ 125 (+443.48%)
Mutual labels:  fastify
fastify-env
Fastify plugin to check environment variables
Stars: ✭ 129 (+460.87%)
Mutual labels:  fastify
fastify-awilix
Dependency injection support for fastify
Stars: ✭ 52 (+126.09%)
Mutual labels:  fastify
Natours
An awesome tour booking web app written in NodeJS, Express, MongoDB 🗽
Stars: ✭ 94 (+308.7%)
Mutual labels:  nodemailer
arc
Fullstack open source Invoicing application made with MongoDB, Express, React & Nodejs (MERN)
Stars: ✭ 1,291 (+5513.04%)
Mutual labels:  nodemailer
fastify-register-routes
Plugin to automatically load routes from a specified path and optionally limit loaded file names by a regular expression.
Stars: ✭ 15 (-34.78%)
Mutual labels:  fastify
fastify-postgres
Fastify PostgreSQL connection plugin
Stars: ✭ 144 (+526.09%)
Mutual labels:  fastify
node-mysql
Node with mysql boilerplate
Stars: ✭ 72 (+213.04%)
Mutual labels:  nodemailer
TvrboReact
Dream starter project: React, Redux, React Router, Webpack
Stars: ✭ 13 (-43.48%)
Mutual labels:  nodemailer
node-server-template
This is Node.js server tidy template / boilerplate with Express (with asyncified handlers, custom error handler) framework and MongoDb. The server use ES6 and above. On different branches you can see different techniques' and technologies' usage, such as Kafka, nodemailer, file download... You also can find postman collections.
Stars: ✭ 116 (+404.35%)
Mutual labels:  nodemailer
fastify-hasura
A Fastify plugin to have fun with Hasura.
Stars: ✭ 30 (+30.43%)
Mutual labels:  fastify

fastify-nodemailer

js-standard-style Build Status Known Vulnerabilities Coverage Status 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

Versions

The plugin supports the following Fastify and Nodemailer versions. Please refer to corresponding branch in PR and issues.

version branch fastify nodemailer End of support
1.x 1.x 1.x 4.x EOL
2.x 2.x 2.x 4.x TBD
3.x master 2.x 5.x Deprecated
4.x 4.x 2.x 6.x TBD
5.x master 3.x 6.x TBD

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

  nodemailer.sendMail({
    from: '[email protected]',
    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}`)
})

Custom transports

By default, passing an object as options to the plugin will configure nodemailer's main transport (SMTP).

If you need a custom transport, simply initialize the transport, and pass it to the plugin instead of an options object. For example, using the nodemailer-sparkpost-transport:

const fastify = require('fastify')()

const sparkPostTransport = require('nodemailer-sparkpost-transport')

const sparkPostTransportOptions = {
  sparkPostApiKey: 'MY_API_KEY'
}

fastify.register(require('fastify-nodemailer'), sparkPostTransport(sparkPostTransportOptions))

// or

const sparkPostTransportInstance = sparkPostTransport(sparkPostTransportOptions)

fastify.register(require('fastify-nodemailer'), sparkPostTransportInstance)

Then, later:

fastify.get('/sendmail', (req, reply, next) => {

  const sendOptions = {
    content: {
      template_id: 'my_template_id',
      use_draft_template: false
    },
    "recipients": [
      {
        "address": {
          "email": "[email protected]",
          "name": "John Doe"
        },
        "substitution_data": {
          username: "John Doe"
        }
      }
    ]
  };

  fastify.nodemailer.sendMail(sendOptions, (err, info) => {
    if (err) next(err)
    reply.send({
      messageId: info.messageId
    })
  })

})

Multiple transports

Since fastify-nodemailer fully supports Fastify's built-in encapsulation feature, all you need to do is register this plugin with your custom transporter and the corresponding route in a new context.

License

Licensed under MIT.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].