Short answer: to send email with a REST API in Node.js, make a POST request with fetch (built into Node 18+) to the provider's send endpoint, with your API key in the Authorization header and a JSON body containing from, to, subject and html. No SDK is needed — see Option 2 for the full code.
There are two good ways to send email from Node.js: over SMTP with Nodemailer, or with a plain fetch call to a REST API. Node.js 18 or newer is enough for either — you'll also need a Sendcorex account and a verified sending domain (publish the SPF, DKIM and DMARC records the dashboard gives you before you send anything real).
Option 1: Nodemailer (SMTP)
npm install nodemailer
import nodemailer from 'nodemailer';
const transporter = nodemailer.createTransport({
host: 'smtp.sendcorex.com',
port: 587,
secure: false, // STARTTLS on 587
auth: { user: process.env.SENDCOREX_API_KEY, pass: process.env.SENDCOREX_API_KEY },
});
const info = await transporter.sendMail({
from: '"Your App" <hello@yourdomain.com>',
to: 'customer@example.com',
subject: 'Welcome!',
text: 'You are in.',
html: '<h1>You are in.</h1>',
});
console.log('Sent:', info.messageId);
Option 2: REST API with fetch
No dependencies, works in serverless and edge runtimes where outbound SMTP is often blocked:
const response = await fetch('https://graph.sendcorex.com/v3.0/emails', {
method: 'POST',
headers: {
Authorization: `Bearer ${process.env.SENDCOREX_API_KEY}`,
'Content-Type': 'application/json',
},
body: JSON.stringify({
to: 'customer@example.com',
from: 'hello@yourdomain.com',
subject: 'Welcome!',
html: '<h1>You are in.</h1>',
}),
});
if (!response.ok) throw new Error(`Send failed: ${response.status}`);
Errors and retries
| Symptom | Fix |
|---|---|
Invalid login | API key missing or wrong — check the env var loaded and has no stray whitespace. |
ETIMEDOUT | The host blocks the SMTP port — try 587/465, or switch to the REST API. |
| Lands in spam | Check SPF/DKIM in a real Gmail header, send text and html, ramp volume gradually. |
4xx responses mean the request itself is wrong — don't retry. 429 and 5xx are temporary — retry with exponential backoff.