{"record":{"id":"3ce118e6177e90ce","repo":"nextauthjs/next-auth","slug":"nodemailer-requires-a-server-configuration","errorCode":null,"errorMessage":"Nodemailer requires a `server` configuration","messagePattern":"Nodemailer requires a `server` configuration","errorType":"validation","errorClass":"AuthError","httpStatus":null,"severity":"error","filePath":"packages/core/src/providers/nodemailer.ts","lineNumber":55,"sourceCode":"    expires: Date\n    provider: NodemailerConfig\n    token: string\n    theme: Theme\n    request: Request\n  }) => Awaitable<void>\n  options?: NodemailerUserConfig\n}\n\nexport type NodemailerUserConfig = Omit<\n  Partial<NodemailerConfig>,\n  \"options\" | \"type\"\n>\n\nexport default function Nodemailer(\n  config: NodemailerUserConfig\n): NodemailerConfig {\n  if (!config.server)\n    throw new AuthError(\"Nodemailer requires a `server` configuration\")\n\n  return {\n    id: \"nodemailer\",\n    type: \"email\",\n    name: \"Nodemailer\",\n    server: { host: \"localhost\", port: 25, auth: { user: \"\", pass: \"\" } },\n    from: \"Auth.js <no-reply@authjs.dev>\",\n    maxAge: 24 * 60 * 60,\n    async sendVerificationRequest(params) {\n      const { identifier, url, provider, theme } = params\n      const { host } = new URL(url)\n      const transport = createTransport(provider.server)\n      const result = await transport.sendMail({\n        to: identifier,\n        from: provider.from,\n        subject: `Sign in to ${host}`,\n        text: text({ url, host }),\n        html: html({ url, host, theme }),","sourceCodeStart":37,"sourceCodeEnd":73,"githubUrl":"https://github.com/nextauthjs/next-auth/blob/a1a16a5a7780488c7449feece410033f445d0b31/packages/core/src/providers/nodemailer.ts#L37-L73","documentation":"An AuthError thrown at provider construction time: Nodemailer(config) requires a `server` property (SMTP transport options for nodemailer) to create the email transport. Without it, the library cannot build a transporter, so it fails immediately rather than at send time. This is purely a configuration error thrown when the provider is created.","triggerScenarios":"Calling Nodemailer({}) or Nodemailer({ from: ... }) without a server field — e.g. process.env.EMAIL_SERVER is undefined so JSON.parse yields nothing, or the developer simply omitted server. The guard `if (!config.server)` throws before returning the provider config.","commonSituations":"Missing EMAIL_SERVER env var in the deployment environment (works locally, fails in prod); forgetting to JSON.stringify the SMTP URL into an env var; renaming config keys during an upgrade from NextAuth v4 to Auth.js v5 where defaults changed.","solutions":["Pass server: { host, port, auth: { user, pass } } (or a nodemailer SMTP URL string) to Nodemailer()","Ensure the EMAIL_SERVER env var is defined in the target environment and parsed before constructing the provider","Log/validate the email config at startup so missing server values fail fast with a clear message","If using a JSON env var, wrap JSON.parse in a try/catch and assert the result has host/port"],"exampleFix":"// before\nNodemailer({ from: \"no-reply@example.com\" }) // no server -> AuthError\n// after\nimport Nodemailer from \"@auth/core/providers/nodemailer\"\nNodemailer({\n  server: {\n    host: process.env.EMAIL_SERVER_HOST,\n    port: Number(process.env.EMAIL_SERVER_PORT),\n    auth: { user: process.env.EMAIL_SERVER_USER, pass: process.env.EMAIL_SERVER_PASS },\n  },\n  from: \"no-reply@example.com\",\n})","handlingStrategy":"validation","validationCode":"const server = process.env.EMAIL_SERVER\n  ? JSON.parse(process.env.EMAIL_SERVER)\n  : undefined\nif (!server?.host) throw new Error('EMAIL_SERVER must define at least { host, port, auth }')","typeGuard":"function hasSmtpServer(c: { server?: { host?: string; port?: number } }): c is { server: { host: string; port: number } } {\n  return typeof c.server?.host === 'string' && typeof c.server?.port === 'number'\n}","tryCatchPattern":"let provider\ntry {\n  provider = Nodemailer(config)\n} catch (e) {\n  if (e instanceof AuthError && e.message.includes('requires a `server` configuration')) {\n    console.error('Nodemailer misconfigured: EMAIL_SERVER missing at startup')\n    throw e // fail fast — email sign-in cannot work without SMTP\n  }\n  throw e\n}","preventionTips":["Define EMAIL_SERVER (or explicit host/port/auth vars) in every environment, including prod","Parse/validate SMTP config at app startup so misconfig fails immediately","After upgrading NextAuth/Auth.js, re-check provider option names for breaking changes","Wrap JSON.parse of the SMTP env var in try/catch with a clear error"],"tags":["config","smtp","nodemailer","autherror","missing-config"],"backgroundTag":"missing-config-property","analyzedSha":"a1a16a5a7780488c7449feece410033f445d0b31","analyzedAt":"2026-08-28T21:52:38.200Z","schemaVersion":2},"datasetVersion":"2026-08-29T02:17:18.158Z"}