uSend Docs
SMTP guides

Nodemailer

Send through usend from Node.js with Nodemailer over SMTP.

Nodemailer is the most common SMTP library for Node.js. Settings used on this page: host smtp.usend.et, port 465 (implicit TLS) or 587 (STARTTLS), username usend, password your API key. The full reference is Send with SMTP.

Create a transport

mail.mjs
import nodemailer from 'nodemailer';

export const transport = nodemailer.createTransport({
  host: 'smtp.usend.et',
  port: 465,
  secure: true, // true for 465; false with port 587 (Nodemailer upgrades with STARTTLS)
  auth: { user: 'usend', pass: process.env.USEND_API_KEY },
  pool: true, // reuse connections
  maxConnections: 3,
});

For port 587:

JavaScript
nodemailer.createTransport({
  host: 'smtp.usend.et',
  port: 587,
  secure: false,
  requireTLS: true, // refuse to continue if STARTTLS is not available
  auth: { user: 'usend', pass: process.env.USEND_API_KEY },
});

Send

JavaScript
import { transport } from './mail.mjs';

const info = await transport.sendMail({
  from: 'Acme <[email protected]>',
  to: '[email protected]',
  subject: 'Hello from usend',
  text: 'It works!',
  html: '<p>It works!</p>',
  attachments: [{ filename: 'invoice.pdf', path: './invoice.pdf' }],
});
console.log(info.response); // 250 ...

Good to know

  • The from address must be on a verified domain of your organization.
  • usend answers 250 when it has accepted the message. SMTP does not return the email id; the email appears in the dashboard logs, and delivery results arrive as webhooks.
  • The limit is 10 messages per second per key. If you send in a loop, keep pool: true and let Nodemailer queue the rest, or use rateLimit/rateDelta in the transport options.
  • A 554 is a refusal you should not retry (domain not verified, organization suspended). A 421, 451 or 452 is temporary: retry later. See the error table.

Prefer the SDK?

If you are starting fresh, the Node.js SDK returns the email id and supports scheduling, tags and templates, which SMTP cannot.