Auth & backend
Verify signup emails in Convex with an action and the scheduler
Schedule a Convex action from the mutation that creates a user, verify the email with fetch, store the verdict through an internal mutation and retry on errors.
Updated 2026-11-26
This recipe verifies the email of every new user of a Convex app in the background. The mutation that creates the user schedules an action; the action calls the API with fetch, then stores the verdict through an internal mutation in an emailChecks table. Your functions read that table to block or limit accounts with an undeliverable or disposable address. There is no native Qelka component for Convex: you add two files and one line.
The recipe does not depend on how users sign in. It hooks onto the mutation that inserts your user document, whether that is your own signup mutation, the user-creating callback of Convex Auth, or the internal mutation that syncs users from Clerk, Auth0 or WorkOS.
What you need
- A Convex project with a
userstable, and the Convex CLI (npx convex dev). - A Qelka API key. A
sk_test_key returns simulated results and never spends credits: see Test mode. A restricted key limited toemailis enough.
Steps
1. Store the key
npx convex env set QELKA_API_KEY sk_test_your_key
npx convex env set QELKA_API_KEY sk_live_your_key --prod
The first line sets it on your development deployment, the second on production. The dashboard's Deployment Settings show and edit the same variables, which keeps the key out of your shell history.
2. Add a table for the verdicts
In convex/schema.ts, next to your existing tables:
import { defineSchema, defineTable } from 'convex/server'
import { v } from 'convex/values'
export default defineSchema({
users: defineTable({
email: v.string(),
}),
emailChecks: defineTable({
userId: v.id('users'),
status: v.string(),
reason: v.string(),
disposable: v.boolean(),
suggestion: v.union(v.string(), v.null()),
checkedAt: v.number(),
}).index('by_user', ['userId']),
})
Keep your own users definition; only emailChecks is new. A separate table leaves the users table, and any auth library that manages it, untouched.
3. The internal mutation that saves a verdict
Save as convex/emailChecks.ts:
import { v } from 'convex/values'
import { internalMutation, type QueryCtx } from './_generated/server'
import type { Id } from './_generated/dataModel'
export const save = internalMutation({
args: {
userId: v.id('users'),
status: v.string(),
reason: v.string(),
disposable: v.boolean(),
suggestion: v.union(v.string(), v.null()),
},
returns: v.null(),
handler: async (ctx, args) => {
const record = { ...args, checkedAt: Date.now() }
const existing = await ctx.db
.query('emailChecks')
.withIndex('by_user', (q) => q.eq('userId', args.userId))
.unique()
if (existing) await ctx.db.patch('emailChecks', existing._id, record)
else await ctx.db.insert('emailChecks', record)
return null
},
})
export async function hasBlockedEmail(ctx: QueryCtx, userId: Id<'users'>) {
const check = await ctx.db
.query('emailChecks')
.withIndex('by_user', (q) => q.eq('userId', userId))
.unique()
return check !== null && (check.status === 'undeliverable' || check.disposable)
}
It is internal, so no client can write a verdict. hasBlockedEmail is a plain helper your queries and mutations call; a user without a row yet, or with unchecked, is not blocked.
4. The action that calls the API
Save as convex/emailCheck.ts:
'use node'
import { v } from 'convex/values'
import { internal } from './_generated/api'
import { internalAction } from './_generated/server'
type EmailResult = {
status: string
reason: string
did_you_mean: string | null
checks: { disposable: boolean }
}
type Lookup = { result: EmailResult } | { retryAfterSeconds: number } | { failed: string }
async function verifyEmail(email: string): Promise<Lookup> {
let response: Response
try {
response = await fetch('https://api.qelka.com/v1/email', {
method: 'POST',
headers: {
Authorization: `Bearer ${process.env.QELKA_API_KEY}`,
'Content-Type': 'application/json',
},
body: JSON.stringify({ email, mode: 'fast' }),
signal: AbortSignal.timeout(10000),
})
} catch {
console.warn('email check failed: unreachable')
return { retryAfterSeconds: 30 }
}
if (response.ok) return { result: (await response.json()) as EmailResult }
const failure = await response.json().catch(() => null)
const type = failure?.error?.type ?? `http_${response.status}`
console.warn(`email check failed: ${type} request ${response.headers.get('X-Request-Id')}`)
if ([429, 500, 502, 503].includes(response.status)) {
return { retryAfterSeconds: Number(response.headers.get('Retry-After')) || 30 }
}
return { failed: type }
}
export const checkSignupEmail = internalAction({
args: { userId: v.id('users'), email: v.string(), attempt: v.number() },
returns: v.null(),
handler: async (ctx, { userId, email, attempt }): Promise<null> => {
const lookup = await verifyEmail(email)
if ('result' in lookup) {
await ctx.runMutation(internal.emailChecks.save, {
userId,
status: lookup.result.status,
reason: lookup.result.reason,
disposable: lookup.result.checks.disposable,
suggestion: lookup.result.did_you_mean,
})
return null
}
if ('retryAfterSeconds' in lookup && attempt < 3) {
await ctx.scheduler.runAfter(lookup.retryAfterSeconds * 1000 * attempt, internal.emailCheck.checkSignupEmail, {
userId,
email,
attempt: attempt + 1,
})
return null
}
await ctx.runMutation(internal.emailChecks.save, {
userId,
status: 'unchecked',
reason: 'failed' in lookup ? lookup.failed : 'unreachable',
disposable: false,
suggestion: null,
})
return null
},
})
The 'use node' directive runs this file in Convex's Node.js runtime, where fetch and AbortSignal.timeout are standard. A file with that directive may only define actions, which is why the mutation lives in its own file. The explicit Promise<null> return type lets TypeScript resolve the action's reference to itself.
mode: 'fast' runs the syntax, DNS and list checks and skips the mailbox check, which waits on the recipient's mail server. It still catches typos, dead domains and disposable inboxes. See the email reference.
5. Schedule it where the user is created
In the mutation that inserts the user, add one line after the insert:
import { v } from 'convex/values'
import { internal } from './_generated/api'
import { internalMutation } from './_generated/server'
export const createUser = internalMutation({
args: { email: v.string() },
returns: v.id('users'),
handler: async (ctx, { email }) => {
const userId = await ctx.db.insert('users', { email })
await ctx.scheduler.runAfter(0, internal.emailCheck.checkSignupEmail, { userId, email, attempt: 1 })
return userId
},
})
Convex schedules the action only if this mutation commits, so a failed signup never spends a credit, and a successful one is always checked. If you use Convex Auth, its API for creating users changed in version 2: put the same runAfter line in whichever user-creating function your version calls.
6. Act on the verdict
status |
Meaning | What to do |
|---|---|---|
undeliverable |
Bad syntax, or a domain that does not exist or takes no mail | Block costly actions, show suggestion and ask for a new address |
risky with disposable: true |
A disposable inbox service | Block trials and invites, or flag for review |
risky, other reasons |
A catch-all domain or a full mailbox | Allow |
unknown |
In fast mode, smtp_not_checked: nothing wrong was found |
Allow |
unchecked |
Three failed attempts, or a key or balance problem | Allow, and check again later |
Call hasBlockedEmail(ctx, userId) at the top of the mutations that matter, such as starting a trial, and throw a ConvexError with a clear message when it is true. Because the check finishes a few seconds after signup, read it where the cost is, not in the signup itself. Never block on unknown. Block disposable email signups helps you decide between blocking and flagging.
7. Test it
With npx convex dev running and a test key set, call your user-creating mutation with disposable@example.com, nomx@example.com and jane@example.com. The emailChecks table in the dashboard fills within seconds: risky with disposable: true, undeliverable with domain_no_mx, and unknown with smtp_not_checked. The action's log lines appear in the dashboard's logs.
Handle errors and rate limits
Nothing is billed on errors. Timeouts, 429, 500, 502 and 503 reschedule the action, waiting Retry-After seconds when the API sends it, and the third failure stores unchecked. 401, 402 and 403 mean a wrong key, an empty balance or a key restricted to other endpoints: they are stored as unchecked with the error type as the reason, so query for them and alert yourself. A key allows 200 requests per 10 seconds, and each email check costs 1 credit. For users created before you added the check, schedule the action in small waves from a one-off internal mutation, or export the addresses and run a bulk file check. See Errors and Rate limits.
Related
Frequently asked questions
Why schedule an action instead of calling the API in the mutation?
What happens when the API call fails?
Where do I keep the API key in Convex?
More in Auth & backend
All integrationsPut this check in your product
Get an API key in under a minute. 100 free credits every month, no card required.
- 100 free credits a month
- No card
- Test keys spend nothing
- Cancel any time