@dzangolab/fastify-mailer
v0.87.0
Published
Fastify mailer plugin
Downloads
968
Readme
@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-mailer html-to-text mustache nodemailer nodemailer nodemailer-html-to-text nodemailer-mjmlInstall with pnpm:
pnpm add --filter "@scope/project" @dzangolab/fastify-mailer html-to-text mustache nodemailer nodemailer nodemailer-html-to-text nodemailer-mjmlUsage
Register Plugin
Register @dzangolab/fastify-mailer package with your Fastify instance:
import mailerPlugin from "@dzangolab/fastify-mailer";
import Fastify from "fastify";
import config from "./config";
const start = async () => {
// Create fastify instance
const fastify = Fastify({
logger: config.logger,
});
// Register mailer plugin
await fastify.register(mailerPlugin, config.mailer);
await fastify.listen({
port: config.port,
host: "0.0.0.0",
});
};
start();Configuration
To configure the mailer, add the following settings to your config/mailer.ts file:
import type { MailerConfig } from "@dzangolab/fastify-mailer";
const mailerConfig: MailerConfig = {
defaults: {
from: {
address: "[email protected]",
name: "Test",
},
},
test: {
enabled: true,
path: "/test/email",
to: "[email protected]",
},
templating: {
templateFolder: "mjml/templates",
},
templateData: {
baseCDNUrl: "http://localhost:3000/",
},
transport: {
auth: {
pass: "pass",
user: "user",
},
host: "localhost",
port: 3001,
requireTLS: true,
secure: true,
},
};
export default mailerConfig;