Send email from NestJS over SMTP
Inject a Nodemailer transport in NestJS and send over Unitpost SMTP. Same credentials as any other stack.
What are the SMTP settings?
| Host | smtp.unitpost.com |
|---|---|
| Username | unitpost(always this literal value) |
| Password | Your Unitpost API key(must carry emails:send) |
| Port (STARTTLS) | 587(or 2587 if blocked) |
| Port (implicit TLS) | 465(or 2465 if blocked) |
| From address | Any address on a verified domain |
How do I set it up?
Install Nodemailer
Shellnpm install nodemailer npm install -D @types/nodemailerProvide a transporter
TypeScriptimport { 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>", }); } }Verify delivery
The send shows up in Activity. See also Nodemailer.