@dzangolab/fastify-mailer
TypeScript icon, indicating that this package has built-in type declarations

0.72.1 • Public • Published

@dzangolab/fastify-mailer

A Fastify plugin that when registered on a Fastify instance, will decorate it with a mailer object for email.

Requirements

Installation

Install with npm:

npm install @dzangolab/fastify-config @dzangolab/fastify-mailer html-minifier html-to-text mustache nodemailer nodemailer nodemailer-html-to-text nodemailer-mjml

Install with pnpm:

pnpm add --filter "@scope/project"  @dzangolab/fastify-config @dzangolab/fastify-mailer html-minifier html-to-text mustache nodemailer nodemailer nodemailer-html-to-text nodemailer-mjml

Usage

Register Plugin

Register @dzangolab/fastify-mailer package with your Fastify instance:

import configPlugin from "@dzangolab/fastify-config";
import mailerPlugin from "@dzangolab/fastify-mailer";
import Fastify from "fastify";

import config from "./config";

import type { ApiConfig } from "@dzangolab/fastify-config";
import type { FastifyInstance } from "fastify";

const start = async () => {
  // Create fastify instance
  const fastify = Fastify({
    logger: config.logger,
  });
  
  // Register fastify-config plugin
  await fastify.register(configPlugin, { config });
  
  // Register mailer plugin
  await fastify.register(mailerPlugin);
  
  await fastify.listen({
    port: config.port,
    host: "0.0.0.0",
  });
};

start();

Configuration

Add mailer configuration:

const config: ApiConfig = {
  // ...
  mailer: {
    defaults: {
      from: {
        address: "test@example.com",
        name: "Test",
      },
    },
    test: {
      enabled: true
      path: "/test/email",
      to: "user@example.com"),
    },
    templating: {
      templateFolder: "mjml/templates",
    },
    templateData: {
      baseCDNUrl: "http://localhost:3000/"),
    },
    transport: {
      auth: {
        pass: "pass",
        user: "user",
      },
      host: "localhost",
      port: 3001,
      requireTLS: true,
      secure: true,
    },
  },
};

Readme

Keywords

none

Package Sidebar

Install

npm i @dzangolab/fastify-mailer

Weekly Downloads

477

Version

0.72.1

License

MIT

Unpacked Size

62.7 kB

Total Files

14

Last publish

Collaborators

  • opichon
  • uddhab
  • rameshlohala
  • cpxpratik