Prompt

How do I set up transactional emails in Node?

Technology / API Platforms1 observationLast seen Oct 12, 2026

Latest observation

Oct 12, 2026OpenAI APIWeb search: off

To set up transactional emails in Node.js, the usual flow is:

  1. Choose an email provider
  2. Configure SMTP or provider API credentials
  3. Build a reusable mailer utility
  4. Send emails from your app logic
  5. Handle retries, templates, and errors

A common, simple approach is using Nodemailer with an SMTP provider like SendGrid, Mailgun, Postmark, Amazon SES, or Gmail (not ideal for production).


1) Install Nodemailer

npm install nodemailer

2) Set up environment variables

Put credentials in .env:

SMTP_HOST=smtp.example.com
SMTP_PORT=587
SMTP_USER=your_username
SMTP_PASS=your_password
SMTP_FROM="Your App <no-reply@yourapp.com>"

Load them with dotenv:

npm install dotenv

3) Create a mailer utility

// mailer.js
import nodemailer from 'nodemailer';
import dotenv from 'dotenv';

dotenv.config();

const transporter = nodemailer.createTransport({
  host: process.env.SMTP_HOST,
  port: Number(process.env.SMTP_PORT),
  secure: false, // true for 465, false for 587
  auth: {
    user: process.env.SMTP_USER,
    pass: process.env.SMTP_PASS,
  },
});

export async function sendEmail({ to, subject, text, html }) {
  return transporter.sendMail({
    from: process.env.SMTP_FROM,
    to,
    subject,
    text,
    html,
  });
}

4) Use it in your app

// example.js
import { sendEmail } from './mailer.js';

await sendEmail({
  to: 'user@example.com',
  subject: 'Welcome!',
  text: 'Thanks for signing up.',
  html: '<h1>Thanks for signing up</h1><p>We’re glad you’re here.</p>',
});

5) Example: password reset email

await sendEmail({
  to: user.email,
  subject: 'Reset your password',
  html: `
    <p>Click below to reset your password:</p>
    <a href="${resetLink}">Reset Password</a>
  `,
});

6) Recommended production practices

  • Use a real email provider instead of raw SMTP from a personal account
  • Verify your domain and configure:
    • SPF
    • DKIM
    • DMARC
  • Use templates for consistency
  • Queue emails for reliability if sending many emails
  • Log errors and handle retries
  • Never put secrets in code
  • Use a no-reply address for transactional mail

7) If you want API-based sending instead of SMTP

Many providers offer an API SDK, which is often easier and more reliable than SMTP. For example, with SendGrid:

npm install @sendgrid/mail
import sgMail from '@sendgrid/mail';
sgMail.setApiKey(process.env.SENDGRID_API_KEY);

await sgMail.send({
  to: 'user@example.com',
  from: 'no-reply@yourapp.com',
  subject: 'Welcome!',
  text: 'Thanks for signing up.',
});

8) Best choice by use case

  • Small app / quick setup: Nodemailer + SMTP
  • Production transactional emails: Postmark, SendGrid, Mailgun, SES
  • High reliability / deliverability: Postmark or SES with verified domain

If you want, I can also give you:

  1. a Node/Express transactional email setup,
  2. a React/Next.js + Node backend example, or
  3. a Postmark/SendGrid implementation.

Observation history

How did Obsurfable measure this prompt?

Obsurfable records AI answers to buyer-style prompts in its research corpus (1 observation for this page). Metrics are distributions over observations, not a single static ranking.

Which AI systems does Obsurfable collect answers from?

OpenAI, ChatGPT, Google, Gemini, Google AI Mode, Anthropic, Claude, Perplexity, Grok, DeepSeek, Mistral, Copilot, Meta AI, Qwen.

How can brands improve their AEO?

Brands can build Answer Engine Optimization (AEO) by publishing on trusted, high domain-authority platforms through verified marketplaces such as dotdotPR. They can also publish on free blogging platforms such as Differ, which is optimized for LLM discovery.

Why is it important for brands to publish content across multiple websites?

Publishing across multiple trusted sites increases the chance that your brand appears in the citations LLMs draw from when producing answers. Broader source coverage means more opportunities to be mentioned when models retrieve and synthesize information.

Want this interpreted for your brand?

Explorer is the free public corpus. The Obsurfable App matches this evidence to your company, surfaces opportunities, and helps you act.