sanjeev bhusal
sanjeev bhusal4mo ago

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
Hmza
Hmza4mo ago
Add ‘use node’ on top of the file
sanjeev bhusal
sanjeev bhusalOP4mo ago
It didn't work
Hmza
Hmza4mo ago
Can you send over the file where the function Is
sanjeev bhusal
sanjeev bhusalOP4mo ago
This is the file where I am interacting with nodemailer
Hmza
Hmza4mo ago
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.
sanjeev bhusal
sanjeev bhusalOP4mo ago
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.
sshader
sshader4mo ago
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:
Email({
// @ts-expect-error -- `ctx` argument is missing in types
sendVerificationRequest: async (params, ctx) => {
const { identifier, url, provider, theme } = params;
await ctx.runAction(internal.nodemailer.sendVerificationEmail, {
to: identifier,
from: provider.from,
url,
theme,
server: provider.server
});
},
}),
Email({
// @ts-expect-error -- `ctx` argument is missing in types
sendVerificationRequest: async (params, ctx) => {
const { identifier, url, provider, theme } = params;
await ctx.runAction(internal.nodemailer.sendVerificationEmail, {
to: identifier,
from: provider.from,
url,
theme,
server: provider.server
});
},
}),
(referencing https://github.com/nextauthjs/next-auth/blob/main/packages/core/src/providers/nodemailer.ts)
Oren
Oren4mo ago
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
{
id: "http-email",
name: "Email",
type: "email",
maxAge: 60 * 60 * 24, // Email link will expire in 24 hours
//@ts-expect-error -- `ctx` argument is missing in types
sendVerificationRequest: async ({ identifier, url }, ctx) => {
await ctx.runAction(internal.email.sendVerificationEmail, {
to: identifier,
url,
});
},
},
{
id: "http-email",
name: "Email",
type: "email",
maxAge: 60 * 60 * 24, // Email link will expire in 24 hours
//@ts-expect-error -- `ctx` argument is missing in types
sendVerificationRequest: async ({ identifier, url }, ctx) => {
await ctx.runAction(internal.email.sendVerificationEmail, {
to: identifier,
url,
});
},
},

Did you find this page helpful?