Marketing & email
Verify emails before sending with SendGrid
Verify each address once when it enters your app, store the result, and put a guard in front of the @sendgrid/mail client so undeliverable addresses never get a send.
Updated 2026-11-26
This recipe keeps undeliverable addresses out of your SendGrid sends. You verify an address once, when it enters your app through a signup, an invite or an import, store the result on the record, and route every send through a small guard in front of the official @sendgrid/mail client that skips addresses marked undeliverable. There is no native Qelka integration for SendGrid; this is plain Node.js code in your backend.
Why it matters: SendGrid adds an address to its bounce suppression list after it bounces and suppresses later messages to it, but the bounce already counted. Mailbox providers watch how often your mail bounces, and a high rate pushes your domain toward the spam folder for every recipient, valid ones included. See Email bounces explained.
What you need
- A SendGrid account with a verified sender, as SendGrid requires before it accepts mail, and an API key with Mail Send permission.
- Node.js 18 or later.
- A Qelka API key. A
sk_test_key returns simulated results and never spends credits: see Test mode. - Both keys in environment variables,
SENDGRID_API_KEYandQELKA_API_KEY. Never hardcode either one. - A column on your users or contacts table to store the status, such as
email_status.
Steps
1. Install the two clients
npm install @sendgrid/mail @qelka/sdk
2. Verify when the address arrives
Call this wherever an address enters your system: the signup handler, the "invite a teammate" endpoint, a CSV import job. It returns the status, the reason and a suggested correction, and it never throws on an API problem.
import { ApiConnectionError, ApiError, Client } from '@qelka/sdk'
const verifier = new Client({ apiKey: process.env.QELKA_API_KEY, timeoutMs: 15000 })
export async function checkAddress(email) {
try {
const result = await verifier.email.verify({ email })
return { status: result.status, reason: result.reason, suggestion: result.did_you_mean }
} catch (error) {
if (error instanceof ApiError) {
console.warn(`email check skipped: ${error.type} request ${error.requestId}`)
} else if (error instanceof ApiConnectionError) {
console.warn(`email check skipped: ${error.message}`)
} else {
throw error
}
return { status: 'unchecked', reason: null, suggestion: null }
}
}
The Qelka SDK retries 429, 502 and 503 answers on its own and turns error responses into an ApiError carrying the error type and the request id. The check runs in full mode, which asks the recipient's mail server about the mailbox, so it can take several seconds: that is why the timeout is 15 seconds and why this belongs in a background job rather than in the request a person is waiting on.
When a person is there to fix a typo, use the answer right away. An invite form is the clearest case, since people type colleagues' addresses from memory:
export async function inviteTeammate(team, email) {
const check = await checkAddress(email)
if (check.status === 'undeliverable') {
return {
ok: false,
message: check.suggestion ? `Did you mean ${check.suggestion}?` : 'This address cannot receive mail.',
}
}
const invite = await team.createInvite({ email, emailStatus: check.status, emailReason: check.reason })
return { ok: true, invite }
}
team.createInvite stands for your own persistence code. In a form that must answer fast, send mode: 'fast' instead and run the full check after the record is created, as Validate signup forms explains.
3. Guard every send
Route your sends through one function that reads the stored status. Undeliverable addresses are skipped and logged; every other status, unchecked included, goes out.
import sgMail from '@sendgrid/mail'
sgMail.setApiKey(process.env.SENDGRID_API_KEY)
export async function sendToRecipient(recipient, message) {
if (recipient.emailStatus === 'undeliverable') {
console.info(`send skipped: ${recipient.email} is undeliverable (${recipient.emailReason})`)
return { sent: false, reason: 'undeliverable' }
}
if (message.category === 'marketing' && recipient.emailReason === 'disposable') {
return { sent: false, reason: 'disposable' }
}
try {
await sgMail.send({
to: recipient.email,
from: message.from,
subject: message.subject,
text: message.text,
html: message.html,
})
return { sent: true }
} catch (error) {
console.error(`SendGrid send failed: ${error.code}`, error.response?.body)
throw error
}
}
message.category is your own label for the kind of mail. A password reset goes to whatever address the person gave you, disposable or not, because they asked for it; a newsletter does not. Errors from SendGrid itself are rethrown so your job queue can retry them: the guard only decides whether to send, not how.
4. Decide what each status means for sending
status and reason |
Transactional mail | Marketing mail |
|---|---|---|
deliverable |
Send | Send |
undeliverable, any reason |
Skip, and ask the person to fix their address next time they sign in, with did_you_mean when there is one |
Skip, and remove from lists |
risky with disposable |
Send what they asked for | Skip |
risky with catch_all |
Send | Send, and watch the bounces of these addresses as a group |
risky with mailbox_full |
Send: it may bounce until the owner makes room | Hold, and check again later |
unknown or unchecked |
Send | Send. Re-check later; never delete on this result |
unknown means the checks could not reach a conclusion, often because the provider does not answer mailbox checks or the server greylisted the check. It is not a bad address. The email reference lists every reason.
5. Test the branches
With a sk_test_ key, the part before the @ picks the outcome: undeliverable@example.com is refused, disposable@example.com comes back risky, unknown@example.com comes back unknown, and any other well-formed address is deliverable. Run your guard against these before going live, and use SendGrid's sandbox mode or a test recipient you own for the send itself.
Handle errors and rate limits
Nothing is billed on errors. 401 invalid_api_key and 403 forbidden mean a wrong or restricted key, 402 insufficient_credits an empty balance: all three end as unchecked here, so count unchecked records and alert yourself when the number climbs. The Qelka SDK waits out 429 with Retry-After; a key allows 200 requests per 10 seconds, so verify an import with verifier.email.verifyMany or a bulk file check rather than one call per row. Each check costs 1 credit. See Errors and Rate limits.
Related
Frequently asked questions
Doesn't SendGrid already stop sending to bad addresses?
SendGrid sells its own email validation. Why use this one?
Should I verify the address before every send?
More in Marketing & email
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