SMTP guides
NextAuth.js (Auth.js)
Send Auth.js magic-link emails through usend with the Nodemailer provider.
Auth.js's email provider sends the sign-in link with Nodemailer, so usend works by SMTP settings alone. You need a verified domain and an API key. Reference: Send with SMTP.
Install
npm install next-auth nodemailerEmail sign-in also needs a database adapter, because the verification token must be stored.
Configure the provider
import NextAuth from 'next-auth';
import Nodemailer from 'next-auth/providers/nodemailer';
export const { handlers, auth, signIn, signOut } = NextAuth({
// adapter: PrismaAdapter(prisma), ...
providers: [
Nodemailer({
server: {
host: 'smtp.usend.et',
port: 465,
secure: true,
auth: { user: 'usend', pass: process.env.USEND_API_KEY },
},
from: 'Acme <[email protected]>',
}),
],
});USEND_API_KEY=us_123456789Use port 587 with secure: false if you prefer STARTTLS.
Customize the email
Nodemailer({
server: { /* ... */ },
from: 'Acme <[email protected]>',
async sendVerificationRequest({ identifier, url, provider }) {
const { createTransport } = await import('nodemailer');
await createTransport(provider.server).sendMail({
to: identifier,
from: provider.from,
subject: 'Your Acme sign-in link',
text: `Sign in: ${url}`,
html: `<p><a href="${url}">Sign in to Acme</a></p>`,
});
},
});Tips
frommust be on a verified domain.- The link is single-use, so click tracking should stay off for these emails; usend does not track unless you turn tracking on for the domain.
- In the sandbox, only verified members of your organization receive mail, so real users cannot sign in until you have production access. See Production approval.
- Prefer the API? Use the Next.js quickstart inside a custom
sendVerificationRequest.