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
Variable
Description
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.com→Create App Password
Visit the App Passwords page (requires 2FA) to generate a password for your app.
Open myaccount.google.com→Copy 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
Host
smtp.sendgrid.net
Port
587
Username
apikey
Password is your SendGrid API key
AWS SES
Host
email-smtp.[region].amazonaws.com
Port
587
Username
Your SMTP username from AWS Console
Requires SMTP credentials from AWS SES
Mailgun
Host
smtp.mailgun.org
Port
587
Username
postmaster@[your domain]
Find your domain in Mailgun dashboard
Brevo (Sendinblue)
Host
smtp-relay.brevo.com
Port
587
Username
Your Brevo email
Get SMTP password from account settings
Authentication Failed
Verify your SMTP_USER and SMTP_PASSWORD are correct. For Gmail, ensure you're using an App Password, not your regular password.
Connection Timeout
Check that SMTP_HOST and SMTP_PORT are correct. Port 587 (TLS) is recommended over 465 (SSL).
Environment Variables Not Loading
Make sure variables are set in Vercel project settings or your .env.local file. Restart your development server after adding them.
Emails Going to Spam
Set up SPF, DKIM, and DMARC records for your domain. Use a proper sender name 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
Monitor failed email sends for suspicious activity