Issue with nodemailer
I am trying to send a email using nodemailer. I am using nodemailer to send emails for forget-password functionality.
When I try to deploy my code to convex via "bun convex dev", I get a error "The package "stream" wasn't found on the file system but is built into node. Are you trying tobundle for node? You can use "platform: 'node'" to do that, which will remove this error."
I don't understand where do i add "platform:node" ? I searched convex documentation, stackoverflow but couldn't find anything.
8 Replies
Add ‘use node’ on top of the file
It didn't work
Can you send over the file where the function
Is
This is the file where I am interacting with nodemailer
sorry i'm not be able to respond more briefly right now but convex doesn't support what you are doing. convex backend is not a typical Nodejs environment. you should host the code somewhere else and use convex actions if you want to still use nodemailer. otherwise a good option is https://resend.com/
Resend
Build, test, and send transactional emails at scale.
you mean i host my nodemailer code somewhere else (like a different repo) and do a api call from convex ?
I wanted to hook into convex auth system to do this. Hence, I didn't create any actions.
My understanding is that the
nodemailer
library can only be used from node (which in Convex, is denoted by "use node"
at the top of the file). Convex Auth needs to be set up in Convex's runtime though, so you can't directly import a node file from your auth.ts
.
If you just want to send email, we recommend Resend, which will work in Convex's runtime. If you specifically want to use Nodemailer, I'd try adding an internal node action that actually interacts with nodemailer, and then creating an Email
provider that calls the action as part of sendVerificationRequest
(looking at the Convex Auth code, the I believe sendVerificationRequest
actually has ActionCtx
as a second argument, but the types don't show it right now)
some rough pseudocode for what this might look like:
(referencing https://github.com/nextauthjs/next-auth/blob/main/packages/core/src/providers/nodemailer.ts)hey I was looking for the same solution the default
Email
provider will not work but I use custom http email provider as sshader recommended like this