fastify-mailer-provider

0.1.1 • Public • Published

fastify-mailer-provider

This module provides a way to send email using nodemailer.

Install

npm i fastify-mailer-provider

Usage

Add it to you project with register and you are done!

const fastify = require('fastify')()

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


fastify.get('/sendmail/:email', async (req, reply) => {
    const {email} = req.params

    await fastify.mailer.sendMail({
        from: 'sender@example.com',
        to: email,
        subject: 'foo',
        text: 'bar'
    })
    return reply.status(204).send()
})

fastify.listen({ port: 3000 }, err => {
    if (err) throw err
})

You can also set an email provider for identification:

const fastify = require('fastify')()

fastify.register(require('fastify-mailer-provider'), {
    provider: 'aws', // using aws to send email
    pool: true,
    host: 'smtp.example.com',
    port: 465,
    secure: true,
    auth: {
        user: 'username',
        pass: 'password'
    }
})


fastify.get('/sendmail/:email', async (req, reply) => {
    const {email} = req.params

    await fastify.mailer.aws.sendMail({
        from: 'sender@example.com',
        to: email,
        subject: 'foo',
        text: 'bar'
    })
    return reply.send({
        provider: fastify.mailer.aws.provider // { provider: 'aws' }
    })
})

fastify.listen({ port: 3000 }, err => {
    if (err) throw err
})

You can also set multiply an email providers:

const fastify = require('fastify')()

fastify.register(require('fastify-mailer-provider'), {
    provider: 'aws',
    // ...
})

fastify.register(require('fastify-mailer-provider'), {
    provider: 'google',
    // ...
})

fastify.register(require('fastify-mailer-provider'), {
    provider: 'sendgrid',
    // ...
})

fastify.get('/sendmail/:email', async (req, reply) => {
    const {email} = req.params

    await fastify.mailer.aws.sendMail({ /*...*/ })
    await fastify.mailer.google.sendMail({ /*...*/ })
    await fastify.mailer.sendgrid.sendMail({ /*...*/ })
    // ...
})

fastify.listen({ port: 3000 }, err => {
    if (err) throw err
})

Documentation

More details about nodemailer documentation, see nodemailer docs.

License

MIT License

Readme

Keywords

Package Sidebar

Install

npm i fastify-mailer-provider

Weekly Downloads

1

Version

0.1.1

License

MIT

Unpacked Size

10.9 kB

Total Files

12

Last publish

Collaborators

  • leandroandrade