Gmail + Nodemailer Setup is a fast and reliable method to send emails directly from your Node.js application. Whether you’re sending OTPs, welcome emails, or contact form messages—this simple integration is all you need.
In this guide, you’ll learn the complete Gmail + Nodemailer Setup process in just 4 beginner-friendly steps.

✅ Why Choose Gmail + Nodemailer?
- Free and perfect for personal or small projects
- Quick integration with any Node.js app
- No need to manage an SMTP server
- Secure via Gmail’s App Passwords
🚀 Step 1: Install Nodemailer in Your Project
Use the following command to install Nodemailer:
npm install nodemailer
This adds Nodemailer to your Node.js app and allows email functionality via Gmail SMTP.
🔐 Step 2: Enable Gmail App Password
To allow Nodemailer to access your Gmail:
- Go to Google Account Settings
- Enable 2-Step Verification
- Go to App Passwords
- Choose Mail and name it Nodemailer
- Generate the password and copy the 16-character code
Note: Never use your main Gmail password directly in your code.
⚙️ Step 3: Configure Nodemailer Transporter
Create a mailer.js
file and paste the following configuration:
const nodemailer = require("nodemailer");
const transporter = nodemailer.createTransport({
service: "gmail",
auth: {
user: "yourgmail@gmail.com",
pass: "your-app-password", // Use the generated App Password here
},
});
module.exports = transporter;
This completes the Gmail + Nodemailer Setup and prepares you to send emails.
✉️ Step 4: Send Your First Email
Now test your Gmail + Nodemailer Setup by sending a simple email:
const transporter = require("./mailer");
const mailOptions = {
from: "yourgmail@gmail.com",
to: "recipient@example.com",
subject: "Hello from Nodemailer",
text: "This email was sent using Gmail + Nodemailer setup!",
};
transporter.sendMail(mailOptions, (err, info) => {
if (err) {
return console.error("Error:", err);
}
console.log("Email sent:", info.response);
});
Once you run this, check your inbox (or spam folder).
🛠 Troubleshooting Gmail + Nodemailer Setup
- Make sure you used App Passwords, not your real Gmail password
- Ensure 2FA is enabled in Gmail
- If Gmail blocks sign-in, review your security activity
- For bulk email, use services like SendGrid or Mailgun
❓ Frequently Asked Questions
❓ Is Gmail + Nodemailer Setup free to use?
Yes, it’s free for personal projects, testing, and small applications.
❓ Why is my email not sending?
Make sure your App Password is correct, and Gmail hasn’t blocked the login attempt.
❓ Can I use Gmail + Nodemailer in production?
For production, Gmail has daily sending limits. It’s better to use transactional email services for scaling.
🏁 Conclusion
Your Gmail + Nodemailer Setup is now complete! By following these 4 easy steps, you’ve enabled your Node.js app to send emails securely and reliably.
💡 Pro Tip: Store your credentials using
.env
files to keep them secure in production.
READ: HTML Tips and Tricks 2025: Top 10 Expert Tips for Web Developers
3 Comments