npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

@asjas/fastify-nodemailer

v1.0.8

Published

A scoped Fastify plugin wrapping Nodemailer for easy email sending.

Readme

@asjas/fastify-nodemailer

A Fastify plugin to integrate Nodemailer for sending emails. This plugin allows you to share a single Nodemailer transporter instance across your Fastify server, simplifying email functionality in your application.

Features

  • Seamless integration with Fastify's plugin system.
  • Share a single Nodemailer transporter across your server.
  • Support for SMTP connection pooling for improved performance.
  • Compatibility with Fastify's encapsulation for multiple transports.
  • TypeScript support for type-safe development.

Install

npm i --save-exact @asjas/fastify-nodemailer

Compatibility

The plugin supports the following Fastify and Nodemailer versions.

NPM Version | Branch | Fastify | Nodemailer | End of support --------|--------|---------|------------|--------------- 1.x | main | 5.x | 7.x | TBD

Usage

Register the plugin with your Fastify server and provide Nodemailer transport options. The options passed to register are forwarded to Nodemailer's createTransport function. Refer to the Nodemailer documentation for detailed configuration options.

Example

import Fastify from 'fastify';
import fastifyNodemailerPlugin from '@asjas/fastify-nodemailer';

const fastify = Fastify();

fastify.register(fastifyNodemailerPlugin, {
  host: 'smtp.example.com',
  port: 587,
  secure: false, // Use true for port 465, false for other ports
  auth: {
    user: '[email protected]',
    pass: 'your-password',
  },
});

// Example route to send an email
fastify.post('/send-email', async (request, reply) => {
  try {
    const info = await fastify.nodemailer.sendMail({
      from: '[email protected]',
      to: '[email protected]',
      subject: 'Test Email',
      text: 'This is a test email!',
    });
    return { message: 'Email sent', info };
  } catch (err) {
    fastify.log.error('Error sending email:', err);
    reply.status(500).send({ error: 'Failed to send email' });
  }
});

fastify.listen({ port: 3000 }, (err) => {
  if (err) throw err;
  console.log('Server running on http://localhost:3000');
});

Connection Pooling

For applications sending multiple emails, you can enable SMTP connection pooling to improve performance by reusing connections. Configure pooling by setting pool: true and related options:

fastify.register(fastifyNodemailerPlugin, {
  host: 'smtp.example.com',
  port: 587,
  secure: false,
  auth: {
    user: '[email protected]',
    pass: 'your-password',
  },
  pool: true, // Enable connection pooling
  maxConnections: 5, // Maximum concurrent connections (default: 5)
  maxMessages: 50, // Maximum messages per connection (default: 100)
  rateLimit: 5, // Maximum 5 emails per second
  rateDelta: 1000, // Rate limit window (1 second)
});

See the Nodemailer SMTP documentation for more details on pooling options.

Multiple Transports

Thanks to Fastify's encapsulation, you can register multiple instances of the plugin with different transporters in separate contexts. For example:

fastify.register(async (instance) => {
  instance.register(fastifyNodemailerPlugin, {
    host: 'smtp.service1.com',
    port: 587,
    secure: false,
    auth: {
      user: '[email protected]',
      pass: 'password1',
    },
  });
  instance.post('/send-email-service1', async (request, reply) => {
    // Use service1 transporter
    await instance.nodemailer.sendMail({ /* email options */ });
  });
});

fastify.register(async (instance) => {
  instance.register(fastifyNodemailerPlugin, {
    host: 'smtp.service2.com',
    port: 587,
    secure: false,
    auth: {
      user: '[email protected]',
      pass: 'password2',
    },
  });
  instance.post('/send-email-service2', async (request, reply) => {
    // Use service2 transporter
    await instance.nodemailer.sendMail({ /* email options */ });
  });
});

License

Licensed under MIT.