SMTP Setup Guide

Configure email sending for your application

Environment Variables
Required configuration for SMTP email sending
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

Gmail Setup
Step-by-step guide for Gmail SMTP
1

Enable 2-Factor Authentication

Go to your Google Account and enable 2-factor authentication if you haven't already.

Open myaccount.google.com
2

Create App Password

Visit the App Passwords page (requires 2FA) to generate a password for your app.

Open myaccount.google.com
3

Copy the App Password

Gmail will provide a 16-character password. Use this as your SMTP_PASSWORD.

4

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.

Code Examples
How to use SMTP in your application

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>',
})
Other Email Providers
SMTP settings for popular email services

SendGrid

Host:smtp.sendgrid.net
Port:587

AWS SES

Host:email-smtp.[region].amazonaws.com
Port:587

Mailgun

Host:smtp.mailgun.org
Port:587

Brevo

Host:smtp-relay.brevo.com
Port:587
Troubleshooting
Common issues and solutions

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.

Security Tips

• 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