Fastify Email Plugin Guide

Register MailPort inside Fastify server instances:

import Fastify from 'fastify';
import { createMailer, smtp } from 'mailport';

const fastify = Fastify({ logger: true });

const mailer = createMailer({
  transport: smtp({
    host: process.env.SMTP_HOST!,
    port: 587,
    auth: {
      user: process.env.SMTP_USER!,
      pass: process.env.SMTP_PASSWORD!,
    },
  }),
});

fastify.post('/send-mail', async (request, reply) => {
  const result = await mailer.send({
    from: 'app@example.com',
    to: 'user@example.com',
    subject: 'Fastify Notification',
    text: 'Sent from Fastify route handler.',
  });

  return { id: result.id };
});

fastify.listen({ port: 3000 });