Skip to main content
Resend Docs

Search documentation

Type to search this documentation.

On this pageOverview

Send emails using NextAuth with SMTP

Before you start, you'll need:

  1. Install

    Install the NextAuth package.

    npm
    npm install next-auth
    yarn
    yarn add next-auth
    pnpm
    pnpm add next-auth
    bun
    bun add next-auth

    Then, install the Nodemailer package.

    npm
    npm install nodemailer
    yarn
    yarn add nodemailer
    pnpm
    pnpm add nodemailer
    bun
    bun add nodemailer
  2. Configure SMTP credentials

    Add your Resend SMTP crendentials in your application's .env file:

    .env
    EMAIL_SERVER_USER=resend
    EMAIL_SERVER_PASSWORD=YOUR_API_KEY
    EMAIL_SERVER_HOST=smtp.resend.com
    EMAIL_SERVER_PORT=465
    EMAIL_FROM=onboarding@resend.dev
  3. Configure Email Provider

    Finally, in your [...nextauth].js file (typically located in pages/api/auth), configure the Email provider with your SMTP settings:

    index.ts
    import NextAuth from 'next-auth';
    import EmailProvider from 'next-auth/providers/email';
    import nodemailer from 'nodemailer';
    
    export default NextAuth({
      providers: [
        EmailProvider({
          server: {
            host: process.env.EMAIL_SERVER_HOST,
            port: process.env.EMAIL_SERVER_PORT,
            auth: {
              user: process.env.EMAIL_SERVER_USER,
              pass: process.env.EMAIL_SERVER_PASSWORD,
            },
          },
          from: process.env.EMAIL_FROM,
        }),
        // ... other providers as needed
      ],
      // ... any other NextAuth.js configs
    });
Suggest an edit

Propose a replacement for this page. The site team reviews it before applying any changes.

Export
Documentation menu