Skip to main content
Version: v4

Email

Install nodemailer​

npm install nodemailer

How to​

The Email provider sends "magic links" via email that the user can click on to sign in. You have likely seen them before if you have used software like Slack.

Adding support for signing in via email in addition to one or more OAuth services provides a way for users to sign in if they lose access to their OAuth account (e.g. if it is locked or deleted).

Configuration is similar to other providers, but the options are different:

pages/api/auth/[...nextauth].js
import EmailProvider from "next-auth/providers/email"
...
providers: [
EmailProvider({
server: process.env.EMAIL_SERVER,
from: process.env.EMAIL_FROM,
// maxAge: 24 * 60 * 60, // How long email links are valid for (default 24h)
}),
],
...

See the Email provider documentation for more information on how to configure email sign in.

note

The email provider requires a database, it cannot be used without one.

Options​

NameDescriptionTypeRequired
idUnique ID for the providerstringNo
nameDescriptive name for the providerstringNo
typeType of provider, in this case email"email"No
serverPath or object pointing to the email serverstring or ObjectNo
sendVerificationRequestCallback to execute to send a verification request, default uses nodemailer(params) => Promise<undefined>No
fromThe email address from which emails are sent, default: "no-reply@example.com"stringNo
maxAgeHow long until the e-mail can be used to log the user in seconds. Defaults to 1 daynumberNo