Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix bug when using nodemailer with SES #11865

Merged
merged 1 commit into from
Sep 25, 2024

Conversation

ninjudd
Copy link
Contributor

@ninjudd ninjudd commented Sep 18, 2024

☕️ Reasoning

I was getting this error when trying to use Nodemailer and NextAuth with SES.

nodemailer/nodemailer#1293

One solution is to expose an SMTP server, but I didn't like that option, so I fixed this issue with a few steps, one of which is this simple patch.

Here is the rest of my code to get this working with the SES client:

import NextAuth from "next-auth"
import { PrismaAdapter } from "@auth/prisma-adapter"
import { prisma } from "@/prisma"
import Nodemailer from "next-auth/providers/nodemailer"
import { SESClient, SendRawEmailCommand } from '@aws-sdk/client-ses';

const sesClient = new SESClient({
  region: 'us-west-2',
});

const ses = {
  config: sesClient.config,
  send: async (command: SendRawEmailCommand) => {
    return await sesClient.send(command);
  }
};
const aws = { SendRawEmailCommand };

export const { handlers, auth, signIn, signOut } = NextAuth({
  adapter: PrismaAdapter(prisma),
  providers: [
    Nodemailer({
      name: "Email",
      server: {
        SES: { ses, aws },
      },
      from: process.env.EMAIL_FROM,
    })
  ]
})

🧢 Checklist

  • Documentation
  • Tests
  • Ready to be merged

🎫 Affected issues

This is the only somewhat related issue I found:
#5136

Copy link

vercel bot commented Sep 18, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
auth-docs ✅ Ready (Inspect) Visit Preview 💬 Add feedback Sep 18, 2024 5:31am
1 Skipped Deployment
Name Status Preview Comments Updated (UTC)
next-auth-docs ⬜️ Ignored (Inspect) Visit Preview Sep 18, 2024 5:31am

Copy link

vercel bot commented Sep 18, 2024

@ninjudd is attempting to deploy a commit to the authjs Team on Vercel.

A member of the Team first needs to authorize it.

@balazsorban44 balazsorban44 merged commit 181c6b8 into nextauthjs:main Sep 25, 2024
6 of 7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
core Refers to `@auth/core` providers
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants