Nodemailer Gmail Setup: How to Get an App Password (FREE & Easy) | Node.js Tutorial
Sending emails from Node.js applications is an essential task for developers. Nodemailer is one of the most popular Node.js libraries for sending emails. In this guide, we will learn how to setup Nodemailer with Gmail using an App Password which is free, secure, and recommended by Google. This tutorial is perfect for developers who want to send automated emails from their Node.js apps without exposing their main Gmail password.
Why Use Gmail App Password with Nodemailer?
Gmail doesn’t allow login using plain password for less secure apps anymore. App Password solves this by providing a special password that can be used only for Nodemailer. Benefits:
- Secure & doesn’t expose your main Gmail password.
- Works with Node.js apps and servers.
- Easy to revoke anytime from Google Account settings.
- Free & official method recommended by Google.
Step by Step: Get Gmail App Password
-
Enable 2-Step Verification on your Gmail account:
Go to Google Account → Security → 2-Step Verification and enable it.
-
Create App Password:
After enabling 2-Step Verification, go to Security → App Passwords. Select Mail and device Other → Node.js and generate a password.
- Copy the 16-character App Password — this will be used in Nodemailer configuration instead of your Gmail password.
Step 1: Install Nodemailer in Node.js Project
Open terminal in your project folder:
npm install nodemailer
Step 2: Configure Nodemailer with Gmail
Use the following example code:
const nodemailer = require('nodemailer');
const transporter = nodemailer.createTransport({
service: 'gmail',
auth: {
user: 'your-email@gmail.com',
pass: 'your-app-password' // 16-character App Password
}
});
const mailOptions = {
from: 'your-email@gmail.com',
to: 'recipient@example.com',
subject: 'Test Email from Node.js',
text: 'Hello! This is a test email sent using Nodemailer and Gmail App Password.'
};
transporter.sendMail(mailOptions, (error, info) => {
if (error) {
console.log('Error:', error);
} else {
console.log('Email sent:', info.response);
}
});
Step 3: Test Your Email
Run your Node.js script:
node index.js
If everything is correct, email will be sent and console will show: Email sent: 250 2.0.0 OK.
Best Practices & Tips
- Never commit your App Password to GitHub or public repos.
- Use environment variables to store email & password.
- Enable SSL/TLS for secure email sending.
- Use descriptive subject and professional content for emails.
Why This Setup is Free & Secure
Google App Password method is completely free. You don’t need any third-party SMTP service. It is secure because it only works for the app and can be revoked anytime from your Google Account.
Advanced Tips
- For bulk emails, consider using transactional email services like SendGrid or Gmail API.
- Handle errors properly in Nodemailer to retry sending if failed.
- Use HTML templates to send professional emails.
Conclusion
Setting up Nodemailer with Gmail using App Password is easy, free, and secure. Follow the steps above and watch the video for live step-by-step guidance. This method will allow you to send automated emails from your Node.js apps safely, without exposing your Gmail credentials.
SEO Keywords: Nodemailer Gmail Setup, Gmail App Password Node.js, Free Email Sending, Node.js Email Tutorial 2025, CodePress Academy.

Hi Please Do not Spam in Comments