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

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

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

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

Troubleshooting
Common issues and solutions

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.

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

Monitor failed email sends for suspicious activity