#Resend api not sending
18 messages · Page 1 of 1 (latest)
If your Resend API is not sending emails in your Convex project, here are some common issues and troubleshooting steps based on the knowledge sources:
-
Test Mode is Enabled
By default, the Resend Convex component runs intestMode, which only allows delivery to test addresses. To send emails to real addresses, you must explicitly settestMode: falsein your Resend component options. Otherwise, emails to non-test addresses will not be sent.export const resend: Resend = new Resend(components.resend, { testMode: false, // Set this to false for production }); -
API Key Configuration
Ensure that your Resend API key is correctly set in your environment variables. For the Convex Auth integration, you typically set it with:npx convex env set AUTH_RESEND_KEY yourresendkeyFor the Resend Convex component, use
RESEND_API_KEY.
Resend Convex Component (Beta) -
Domain Verification
In production, Resend requires your sending domain to be verified. If you haven't verified your domain, emails may not be delivered or may only be sent to test addresses.
Building a Real-World TypeScript App with Convex and Expo
-
Development Quota
In development, emails sent via Resend still count toward your quota. There is no built-in way to bypass Resend or obtain codes without sending an email, but you can implement a workaround by using a different auth method or printing the code in development instead of sending an email.
Discord support thread: Question About Convex Auth Resend Usage in Development Environment -
Error Handling
Always check for errors returned by the Resend API. ThesendVerificationRequestfunction should throw or log errors if sending fails:const { error } = await resend.emails.send({ ... }); if (error) { throw new Error(JSON.stringify(error)); } -
React/Resend Compatibility Issues
If you see errors likeMessageChannel is not defined, this is a known issue with React 19 and Resend/React Email. The workaround is to add a polyfill forMessageChannelas described in the Discord thread:
Discord support thread: Running into some cryptic error. Help needed.
If you have checked all of the above and emails are still not being sent, please provide more details or error messages for further troubleshooting.
Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:
@abstract pine Kapa.ai is still learning and improving, please let me know how I did by reacting below.
is this correct usage of how to send a email using resend and convex
@brazen citrus is this correct usage of how to send a email using resend and convex
Let me check the knowledge base for you again. One moment! :books:
To send an email using Resend and Convex, the recommended approach is to use the official Resend Convex Component. Here’s a minimal, correct example based on the knowledge sources:
-
Install the Resend Convex Component:
npm install @convex-dev/resend -
Add the component to your Convex app in
convex/convex.config.ts:import { defineApp } from "convex/server"; import resend from "@convex-dev/resend/convex.config"; const app = defineApp(); app.use(resend); export default app; -
Set your Resend API key in your environment variables:
npx convex env set RESEND_API_KEY your-resend-api-key -
Send an email from a Convex internal mutation (e.g.,
convex/sendEmails.ts):import { components } from "./_generated/api"; import { Resend } from "@convex-dev/resend"; import { internalMutation } from "./_generated/server"; export const resend: Resend = new Resend(components.resend, { testMode: false, // Set to false to send to real addresses }); export const sendTestEmail = internalMutation({ handler: async (ctx) => { await resend.sendEmail( ctx, "Me <[email protected]>", "Resend <[email protected]>", "Hi there", "This is a test email" ); }, });
Key points:
- Make sure
testModeis set tofalseif you want to send to real (non-test) addresses. - Your API key must be set in the environment as
RESEND_API_KEY. - The
sendEmailmethod takes the context, from, to, subject, and body as arguments.
If you follow these steps, you are using Resend and Convex together correctly. If you encounter issues, double-check your API key, domain verification, and error handling as described in the previous answer.
If you are using Convex Auth and want to send verification or OTP emails, the setup is slightly different and uses provider configs, but the above is the standard pattern for general email sending with Resend and Convex.
Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:
@abstract pine Kapa.ai is still learning and improving, please let me know how I did by reacting below.
@brazen citrus write me a mutation that sends a email like this
Let me check the knowledge base for you again. One moment! :books:
Certainly! Here is a mutation that sends an email using the Resend Convex Component, following the official example from the knowledge sources:
import { components } from "./_generated/api";
import { Resend } from "@convex-dev/resend";
import { mutation } from "./_generated/server";
// Initialize the Resend client
export const resend: Resend = new Resend(components.resend, {
testMode: false, // Set to false to send to real addresses
});
// Mutation to send an email
export const sendEmail = mutation({
args: {
to: v.string(),
subject: v.string(),
body: v.string(),
},
handler: async (ctx, { to, subject, body }) => {
await resend.sendEmail(
ctx,
"Me <[email protected]>", // From address
to, // To address
subject, // Subject
body // Body
);
},
});
Usage:
Call this mutation from your client, passing the recipient, subject, and body.
Make sure you have set your RESEND_API_KEY environment variable and added the Resend component to your Convex app as described in the setup steps.
This pattern is directly based on the official documentation and is the recommended way to send emails with Resend and Convex Resend Convex Component (Beta).
Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:
@abstract pine Kapa.ai is still learning and improving, please let me know how I did by reacting below.
@brazen citrus how come when tesing out i get the resend api cannot be found "use node";
import { action } from "./_generated/server";
import { v } from "convex/values";
import { Resend as ResendAPI } from "resend";
export const sendEmail = action({
args: {
to: v.string(),
subject: v.string(),
body: v.string(),
},
handler: async (ctx, { to, subject, body }) => {
const resend = new ResendAPI(process.env.RESEND_API_KEY!);
const { error } = await resend.emails.send({
from: Clin2 <[email protected]>,
to: [to],
subject,
html: body,
});
if (error) {
throw new Error(Could not send: ${error.message});
}
return null;
},
});
Let me check the knowledge base for you again. One moment! :books:
The error you're encountering—Resend API cannot be found—happens because you are trying to use the Resend SDK (resend NPM package) directly inside a Convex action with "use node". However, Convex actions do not support all Node.js APIs and NPM packages, even with "use node", and the recommended way to use Resend with Convex is via the official @convex-dev/resend component, not by importing the Resend SDK directly.
Key points from the knowledge sources:
- The official and supported way to send emails with Resend in Convex is to use the
@convex-dev/resendcomponent, not theresendNPM package directly. - You should not use
"use node"and the Resend SDK in Convex actions. Instead, set up the Resend component in your Convex app and use its API as shown in the official documentation. - The Resend component handles batching, queueing, and reliability, and is designed to work with Convex's environment Resend Convex Component (Beta).
What you should do:
-
Install the Resend Convex Component:
npm install @convex-dev/resend -
Configure it in your Convex app as described in the docs.
-
Use the Resend component in your mutation or internal mutation, like this:
import { components } from "./_generated/api"; import { Resend } from "@convex-dev/resend"; import { mutation, v } from "./_generated/server"; export const resend: Resend = new Resend(components.resend, { testMode: false, });
export const sendEmail = mutation({
args: {
to: v.string(),
subject: v.string(),
body: v.string(),
},
handler: async (ctx, { to, subject, body }) => {
await resend.sendEmail(
ctx,
"Clin2 [email protected]",
to,
subject,
body
);
},
});
This approach is supported and will not result in the "Resend API cannot be found" error.
**Summary:**
You are seeing this error because Convex does not support using the Resend SDK directly in actions, even with `"use node"`. Use the official `@convex-dev/resend` component as described in the documentation for reliable and supported email sending in Convex [Resend Convex Component (Beta)](<https://www.convex.dev/components/resend#resend-convex-component-beta>).
----------------------
Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:
----------------------