How to Send Transactional Emails with Node.js
What are transactional emails?
Transactional emails are triggered by user actions — password resets, order confirmations, welcome emails, account notifications, and two-factor authentication codes. Unlike marketing emails, transactional emails are expected by the recipient and have significantly higher open rates (typically 60-80% vs 15-25% for marketing). They're also critical to your application's functionality: if a password reset email doesn't arrive, your user is locked out. This makes reliability and deliverability non-negotiable for transactional email. You need an email API that prioritizes delivery speed and inbox placement over volume.
Setting up AISend with Node.js
Start by creating a free AISend account at aisend.app — no credit card required. From the dashboard, create an API key. Then install the SDK in your Node.js project: npm install aisend. Initialize the client with your API key, ideally stored in an environment variable. The SDK provides TypeScript types out of the box, so you get full autocomplete and type checking in your IDE. The client handles retries, error formatting, and connection pooling automatically.
Sending your first email
Sending an email requires four fields: from (your verified sending domain), to (the recipient), subject, and either html or text for the body. The SDK returns a response object containing the email ID for tracking, the delivery status, and which provider AI selected for this particular send. For production applications, always use a verified custom domain as your from address — this significantly improves deliverability compared to using a shared domain.
import { AISend } from "aisend";
const aisend = new AISend(process.env.AISEND_API_KEY!);
const { id, status } = await aisend.emails.send({
from: "hello@mail.yourapp.com",
to: "user@example.com",
subject: "Welcome to YourApp!",
html: "<h1>Welcome!</h1><p>Thanks for signing up.</p>",
});
console.log(`Email ${id} — ${status}`);Common patterns for Node.js apps
For Express.js applications, create a dedicated email service module that wraps the AISend client. This keeps your email logic centralized and testable. For Next.js applications, use API route handlers or server actions to send emails — never expose your API key to the client side. For background email sending, use a job queue like BullMQ to process email sends asynchronously. This prevents email sending from blocking your API response times and provides automatic retry logic for failed sends.
Handling webhooks and delivery events
AISend sends webhook events for every email lifecycle stage: queued, sending, sent, delivered, opened, clicked, bounced, and complained. Set up a webhook endpoint in your application to receive these events in real-time. Each webhook payload is signed with HMAC-SHA256 using your webhook secret, so you can verify that events are genuinely from AISend. Use delivery events to update your application state — mark emails as delivered in your database, trigger follow-up actions on opens, or handle bounces by marking email addresses as invalid. This creates a complete audit trail for every email your application sends.
Related Posts
Ready to Send Smarter Emails?
3,000 emails/month free. No credit card required.