eSMS AfricaeSMS Africa
Guides

SMTP with Nodemailer

Send emails from Node.js using Nodemailer and eSMS Mail SMTP.

Install Nodemailer

npm install nodemailer

Create the transporter

const nodemailer = require('nodemailer');

const transporter = nodemailer.createTransport({
  host: 'send.esmsafrica.io',
  port: 587,
  secure: false, // STARTTLS
  auth: {
    user: 'your_smtp_username',
    pass: 'your_smtp_password',
  },
});

Send an email

async function sendEmail() {
  const info = await transporter.sendMail({
    from: '"My App" <hello@yourdomain.com>',
    to: 'recipient@example.com',
    subject: 'Welcome to My App',
    text: 'Thanks for signing up!',
    html: '<h1>Welcome!</h1><p>Thanks for signing up to My App.</p>',
  });

  console.log('Message sent:', info.messageId);
}

sendEmail();

With attachments

await transporter.sendMail({
  from: '"My App" <hello@yourdomain.com>',
  to: 'recipient@example.com',
  subject: 'Your invoice',
  html: '<p>Please find your invoice attached.</p>',
  attachments: [
    {
      filename: 'invoice.pdf',
      path: './invoices/invoice-001.pdf',
    },
  ],
});

With Express.js

const express = require('express');
const nodemailer = require('nodemailer');

const app = express();
app.use(express.json());

const transporter = nodemailer.createTransport({
  host: 'send.esmsafrica.io',
  port: 587,
  secure: false,
  auth: {
    user: process.env.SMTP_USER,
    pass: process.env.SMTP_PASS,
  },
});

app.post('/api/send-welcome', async (req, res) => {
  const { email, name } = req.body;

  await transporter.sendMail({
    from: '"My App" <hello@yourdomain.com>',
    to: email,
    subject: `Welcome, ${name}!`,
    html: `<h1>Hi ${name}</h1><p>Welcome to our platform.</p>`,
  });

  res.json({ success: true });
});

app.listen(3000);

Getting SMTP credentials

  1. Go to send.esmsafrica.io → Settings → SMTP
  2. Click Create SMTP Credential
  3. Select your verified domain
  4. Copy the username and password

See SMTP documentation for more details.

On this page