typescriptbeginner

Nodemailer Send Email with SMTP

Send transactional emails using Nodemailer with SMTP transport, HTML templates, and attachments.

typescript
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.