A Fastify plugin that when registered on a Fastify instance, will decorate it with a mailer
object for email.
- @dzangolab/fastify-config
- html-minifier
- html-to-text
- mustache
- nodemailer
- nodemailer-html-to-text
- nodemailer-mjml
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
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();
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,
},
},
};