Nodemailer Send Email with SMTP
Send transactional emails using Nodemailer with SMTP transport, HTML templates, and attachments.
import nodemailer from 'nodemailer';
const transporter = nodemailer.createTransport({
host: process.env.SMTP_HOST,
port: Number(process.env.SMTP_PORT) || 587,
secure: false,
auth: {
user: process.env.SMTP_USER,
pass: process.env.SMTP_PASS,
},
});
export async function sendEmail({
to,
subject,
html,
}: {
to: string;
subject: string;
html: string;
}) {
const info = await transporter.sendMail({
from: '"SnippetsLab" <noreply@snippetslab.dev>',
to,
subject,
html,
});
return info.messageId;
}Sponsored
Try Resend — Email API for Developers
Use Cases
- Welcome emails
- Password reset emails
- Order confirmations
Tags
Related Snippets
Similar patterns you can reuse in the same workflow.
Toast Notification System
Build a toast notification system with auto-dismiss, stacking, animations, and severity levels.
Best for: User feedback notifications
JWT Verify Middleware
Express middleware that verifies JWT tokens from the Authorization header and attaches the decoded payload to the request.
Best for: REST API authentication
In-Memory Rate Limiter for Express
Token bucket rate limiter middleware for Express with configurable window and max requests per IP.
Best for: API abuse prevention
Async Error Handler Wrapper
Higher-order function that wraps async Express route handlers and forwards rejected promises to error middleware.
Best for: Express route error handling