SMTP Setup Guide
Configure email sending for your application
SMTP_HOST=smtp.gmail.com SMTP_PORT=587 SMTP_USER=your-email@gmail.com SMTP_PASSWORD=your-app-password SMTP_FROM=noreply@yourapp.com SMTP_FROM_NAME=Your App Name
SMTP_HOST
SMTP server address (e.g., smtp.gmail.com)
SMTP_PORT
SMTP port (587 for TLS, 465 for SSL)
SMTP_USER
Email address for authentication
SMTP_PASSWORD
App password or SMTP password
SMTP_FROM
Default sender email address
SMTP_FROM_NAME
Sender display name
Enable 2-Factor Authentication
Go to your Google Account and enable 2-factor authentication if you haven't already.
Open myaccount.google.comCreate App Password
Visit the App Passwords page (requires 2FA) to generate a password for your app.
Open myaccount.google.comCopy the App Password
Gmail will provide a 16-character password. Use this as your SMTP_PASSWORD.
Set Environment Variables
Add the SMTP variables to your .env.local or Vercel project settings.
Pro Tip
Use Gmail's App Passwords instead of your regular password for better security. Never commit environment variables to version control.
Basic Node.js nodemailer example
import nodemailer from 'nodemailer'
// Create transport
const transporter = nodemailer.createTransport({
host: process.env.SMTP_HOST,
port: parseInt(process.env.SMTP_PORT || '587'),
secure: process.env.SMTP_PORT === '465',
auth: {
user: process.env.SMTP_USER,
pass: process.env.SMTP_PASSWORD,
},
})
// Send email
await transporter.sendMail({
from: process.env.SMTP_FROM,
to: 'recipient@example.com',
subject: 'Hello',
html: '<h1>Welcome</h1>',
})SendGrid
AWS SES
Mailgun
Brevo
Authentication Failed
Verify SMTP credentials. For Gmail, use an App Password, not regular password.
Connection Timeout
Check that SMTP_HOST and SMTP_PORT are correct. Port 587 (TLS) is recommended.
Environment Variables Not Loading
Ensure variables are in .env.local or Vercel settings and restart server.
Emails Going to Spam
Set up SPF, DKIM, and DMARC records and avoid spam trigger words.
• Never commit environment variables to git or public repositories
• Use environment-specific passwords or API keys
• Rotate your SMTP password regularly
• Use TLS (port 587) instead of SSL for better compatibility