Prompt

how to set up transactional email in node

Technology / API Platforms1 observationLast seen Oct 21, 2026

Latest observation

Oct 21, 2026OpenAI APIWeb search: off

To set up transactional email in Node.js, the usual approach is to use an email provider like SendGrid, Mailgun, Amazon SES, Postmark, or Resend and send mail through their API or SMTP.

Here’s a simple, practical setup using Node.js + Nodemailer with SMTP.


1) Install Nodemailer

npm install nodemailer

2) Create a transporter

Example with Gmail SMTP:

const nodemailer = require('nodemailer');

const transporter = nodemailer.createTransport({
  service: 'gmail',
  auth: {
    user: process.env.EMAIL_USER,
    pass: process.env.EMAIL_PASS, // use an app password, not your normal password
  },
});

For production, it’s better to use a dedicated provider like Postmark, SendGrid, or SES rather than Gmail.


3) Send a transactional email

async function sendWelcomeEmail(to) {
  const mailOptions = {
    from: process.env.EMAIL_USER,
    to,
    subject: 'Welcome to our app!',
    text: 'Thanks for signing up!',
    html: '<h1>Welcome!</h1><p>Thanks for signing up!</p>',
  };

  try {
    const info = await transporter.sendMail(mailOptions);
    console.log('Email sent:', info.response);
  } catch (err) {
    console.error('Error sending email:', err);
  }
}

Use it like:

sendWelcomeEmail('user@example.com');

4) Store credentials in environment variables

Create a .env file:

EMAIL_USER=your-email@gmail.com
EMAIL_PASS=your-app-password

Install dotenv:

npm install dotenv

Load it in your app:

require('dotenv').config();

5) Recommended production setup

For reliable transactional email, use a provider such as:

  • Postmark — great for transactional email
  • SendGrid
  • Amazon SES
  • Mailgun
  • Resend

These give you:

  • better deliverability
  • bounce handling
  • logs/analytics
  • templates
  • easier scaling

Example with SendGrid

Install

npm install @sendgrid/mail

Setup

const sgMail = require('@sendgrid/mail');
sgMail.setApiKey(process.env.SENDGRID_API_KEY);

async function sendWelcomeEmail(to) {
  const msg = {
    to,
    from: 'verified-sender@yourdomain.com',
    subject: 'Welcome!',
    text: 'Thanks for signing up!',
    html: '<strong>Thanks for signing up!</strong>',
  };

  try {
    await sgMail.send(msg);
    console.log('Email sent');
  } catch (error) {
    console.error(error);
  }
}

Best practices for transactional email

  • Use a verified domain and sender address
  • Send through a transactional provider
  • Use templates for consistency
  • Keep emails short and clear
  • Include only important content
  • Handle retries and failures
  • Avoid sending transactional and marketing emails from the same system if possible

If you want, I can give you:

  1. a complete Express.js example, or
  2. a setup using Resend / SendGrid / Amazon SES specifically.

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.