Sending Emails with SMTP in Node.js
Send emails through AhaSend’s SMTP servers using Node.js with Nodemailer, the most popular and feature-rich email library for Node.js. This guide covers everything from basic setup to advanced features like attachments and custom headers.Why Nodemailer? Node.js doesn’t have built-in SMTP support, but Nodemailer provides a powerful, well-maintained solution with extensive features including HTML emails, attachments, embedded images, and robust error handling.
Prerequisites
Before you begin, ensure you have:System Requirements
System Requirements
- Node.js installed on your system (Download Node.js)
- npm or yarn package manager
- Basic knowledge of JavaScript and Node.js
AhaSend Setup
AhaSend Setup
- Domain verified in your AhaSend account
- SMTP credentials created (username and password)
- Access to your AhaSend dashboard for credential management
Need SMTP Credentials? If you haven’t created SMTP credentials yet, check out our SMTP Credentials guide for step-by-step instructions.
Installation
Install Nodemailer in your Node.js project:TypeScript Support
Connection Settings
Use these settings for all Nodemailer configurations with AhaSend:Primary Server
Host:
Ports: 587 (recommended), 25, 2525
Security: STARTTLS (requireTLS: true)
Authentication: Required
send.ahasend.comPorts: 587 (recommended), 25, 2525
Security: STARTTLS (requireTLS: true)
Authentication: Required
US Server
Host:
Ports: 587 (recommended), 25, 2525
Security: STARTTLS (requireTLS: true)
Authentication: Required
send-us.ahasend.comPorts: 587 (recommended), 25, 2525
Security: STARTTLS (requireTLS: true)
Authentication: Required
Basic Email Examples
Testing with Sandbox Mode
Use sandbox mode to safely test your Node.js email integration:Sandbox Benefits: Emails sent in sandbox mode are free, trigger webhooks normally, and never actually deliver to recipients - perfect for development and testing.
Environment Variables & Best Practices
Using Environment Variables
Resources
Nodemailer Documentation
Official Nodemailer documentation and examples
AhaSend Support
Get help from our engineering team

