Send email from NestJS over SMTP

Inject a Nodemailer transport in NestJS and send over Unitpost SMTP. Same credentials as any other stack.

Need an API key?

SMTP password is a Unitpost API key with emails:send. Username is always unitpost.

  • 5,000 emails/month
  • 3 API keys
  • 5 sending domains
Get free SMTP key
  1. Install Nodemailer

    Shell
    npm install nodemailer
    npm install -D @types/nodemailer
  2. Provide a transporter

    TypeScript
    import { Injectable } from "@nestjs/common";
    import nodemailer from "nodemailer";
    
    @Injectable()
    export class MailService {
      private transporter = nodemailer.createTransport({
        host: "smtp.unitpost.com",
        port: 587,
        secure: false,
        auth: {
          user: "unitpost",
          pass: process.env.UNITPOST_API_KEY,
        },
      });
    
      sendWelcome(to: string) {
        return this.transporter.sendMail({
          from: "you@yourdomain.com",
          to,
          subject: "Welcome",
          html: "<p>Sent via SMTP.</p>",
        });
      }
    }
  3. Verify delivery

    The send shows up in Activity. See also Nodemailer.

Search docs and guides

Search the docs and product guides.