
This blog shows exactly how to generate Gmail App Passwords and configure the essential SMTP keys in your Next.js project for sending emails using Gmail, Nodemailer, SendGrid, or any email provider.
1. Enable 2-Step Verification
Go to your Google Account Security settings and enable 2-Step Verification if it’s not already enabled, as shown in Figure 1.

2. Navigate to App Passwords
In your Google Account, go to App Passwords, as shown in Figure 2.

3. Generate App Password
Enter an app name of your choice and press Create, as shown in Figure 3.

4. Copy the 16-Character Password
Copy the 16-character password generated by Google, as shown in Figure 4.

Figure 4
5. Paste Keys in .env File
Add the required SMTP configuration into your project’s .env
file:
SMTP_HOST=smtp.gmail.com
SMTP_PORT=587
SMTP_USER=youremail@gmail.com
SMTP_PASS=your-16-character-app-password
By storing these values securely in your .env
file and using a
library like Nodemailer or SendGrid, you
can send emails reliably for contact forms, authentication, or transactional
notifications in your Next.js application.
THANK YOU