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
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:
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
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
fromaddress must be on a verified domain of your organization. - usend answers
250when it has accepted the message. SMTP does not return the emailid; 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: trueand let Nodemailer queue the rest, or userateLimit/rateDeltain the transport options. - A
554is a refusal you should not retry (domain not verified, organization suspended). A421,451or452is 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.