Sheets & data
Validate emails in a Notion database
A Node.js script with the official Notion SDK reads a database through its data source, verifies each page's Email property and writes an Email status select.
Updated 2026-11-26
This recipe checks the email addresses stored in a Notion database. A Node.js script reads every page whose Email status is empty, verifies its Email property with the API, and writes the result to the page: a select for the status and a text property for the suggested correction or the reason. It uses the official Notion SDK and the current Notion API, which reads rows through data sources. There is no Qelka connection in Notion's gallery: the script runs on your machine, a server or a scheduled job.
What you need
- A Notion database with an
Emailproperty of type Email, anEmail statusproperty of type Select and anEmail noteproperty of type Text. - Workspace Owner rights to create an internal connection, or a personal access token (see step 1).
- Node.js 22 or later. The current Notion SDK requires it.
- A Qelka API key. A
sk_test_key returns simulated results and never spends credits: see Test mode. Use a key restricted toemailin the dashboard: see Restricted keys.
Steps
1. Create the Notion connection
- Open Notion's Developer portal at app.notion.com/developers/connections. On the Developer connections tab, select New connection, give it a name, choose API token as the authentication method and create it.
- On the Configuration tab, allow it to read content and update content, then copy the API token.
- Give it access to the database: on the Content access tab, select Edit access and pick the database. Or open the database's page in Notion, select the ••• menu, then Connections, and add your connection.
A personal access token works too, for a script only you run. It acts as you, with access to everything you can see, while an internal connection only reaches the pages you share with it. Prefer the connection for anything that runs unattended.
Then copy the data source ID: in the database's settings, open Manage data sources and choose Copy data source ID.
2. Store the secrets
Create a .env file next to the script, and add it to .gitignore:
NOTION_TOKEN=your-notion-api-token
NOTION_DATA_SOURCE_ID=your-data-source-id
QELKA_API_KEY=sk_test_your_key
On a server or in CI, set the same three values as environment variables or secrets instead of a file.
3. The script
Install the SDK:
npm install @notionhq/client
npm pkg set type=module
Save as verify-notion.js:
import { Client, isFullPage } from '@notionhq/client'
const notion = new Client({
auth: process.env.NOTION_TOKEN,
notionVersion: '2026-03-11',
timeoutMs: 20000,
})
const dataSourceId = process.env.NOTION_DATA_SOURCE_ID
const retryable = new Set([429, 500, 502, 503])
async function verifyEmail(email) {
for (let attempt = 1; attempt <= 3; attempt += 1) {
let 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 }),
signal: AbortSignal.timeout(15000),
})
} catch {
console.error('validation skipped: unreachable')
return null
}
if (response.ok) return response.json()
if (retryable.has(response.status) && attempt < 3) {
const retryAfter = Number(response.headers.get('Retry-After'))
await new Promise((resolve) => setTimeout(resolve, (retryAfter > 0 ? Math.min(retryAfter, 10) : attempt * 2) * 1000))
continue
}
const failure = (await response.json().catch(() => null))?.error?.type ?? `http_${response.status}`
console.error(`validation skipped: ${failure} request ${response.headers.get('X-Request-Id')}`)
if (failure === 'invalid_api_key' || failure === 'insufficient_credits') process.exit(1)
return null
}
return null
}
async function findUnchecked() {
const pages = []
let cursor
do {
const response = await notion.dataSources.query({
data_source_id: dataSourceId,
start_cursor: cursor,
filter: {
and: [
{ property: 'Email', email: { is_not_empty: true } },
{ property: 'Email status', select: { is_empty: true } },
],
},
})
for (const page of response.results) {
if (isFullPage(page)) pages.push(page)
}
cursor = response.has_more ? response.next_cursor : undefined
} while (cursor)
return pages
}
const pages = await findUnchecked()
let checked = 0
let skipped = 0
for (const page of pages) {
const property = page.properties['Email']
const email = property?.type === 'email' ? property.email?.trim() : null
if (!email) continue
const result = await verifyEmail(email)
if (!result) {
skipped += 1
continue
}
try {
await notion.pages.update({
page_id: page.id,
properties: {
'Email status': { select: { name: result.status } },
'Email note': { rich_text: [{ type: 'text', text: { content: result.did_you_mean ?? result.reason } }] },
},
})
checked += 1
} catch (error) {
console.error(`notion update failed for ${page.id}: ${error.code ?? error.message}`)
}
}
console.log(`checked ${checked}, skipped ${skipped}, of ${pages.length} pages`)
Run it with node --env-file=.env verify-notion.js.
What it does, and why:
- It collects every matching page first, then updates them. Writing a status removes a page from the filter, and changing the result set while paging through it can skip rows.
notionVersion: '2026-03-11'opts into Notion's latest API version, which the SDK supports alongside the older2025-09-03. The calls used here behave the same in both.- Notion writes a select option that does not exist yet as a new option, as long as the connection can update the database. Create
deliverable,undeliverable,riskyandunknownyourself beforehand if you want to choose their colors. - The email check runs in the default
fullmode, mailbox check included, with a 15-second timeout: nothing waits on this script, so it can afford the most precise answer. See the email reference. - A failed check writes nothing, so the page is picked up again next run. A wrong key or an empty balance stops the script at once instead of skipping every page.
4. Schedule it
Run the script from cron, a scheduled job on your platform, or a GitHub Actions workflow on a schedule, with the three secrets set there. Each run only checks pages added since the last one, so an hourly run costs nothing when nothing is new.
Use the status
Email status |
Meaning | What to do |
|---|---|---|
deliverable |
The mail server accepted the mailbox | Use it |
undeliverable |
Bad syntax, no domain or no mailbox | Fix it with Email note when it holds a suggestion, or find another address |
risky |
Disposable inbox, catch-all domain or full mailbox | Read the reason in Email note before writing to it |
unknown |
The checks could not conclude | Keep it: not a bad address |
| Empty | Not checked yet, or the check failed | Wait for the next run |
Add a filtered view on Email status is undeliverable to review bad addresses, or group a board by the status.
Handle errors and rate limits
Nothing is billed on errors. The script retries 429, 500, 502 and 503 after Retry-After, then logs the error type and the X-Request-Id and moves to the next page. 401 invalid_api_key and 402 insufficient_credits stop the run, since every other page would fail the same way. A key allows 200 requests per 10 seconds, and each email check costs 1 credit. See Errors and Rate limits.
Notion is usually the slower side. It limits the request rate of each connection, more tightly on plans below Business, and answers 429 rate_limited with a Retry-After header beyond it. The Notion SDK retries rate-limited requests on its own, twice by default, and a query returns at most 10,000 pages, by Notion's current limits. For a database of tens of thousands of rows, export the emails to CSV and run a bulk job instead, then import the statuses back.
Related
Frequently asked questions
Why does the script need a data source ID instead of a database ID?
Will the script check the same rows every time it runs?
Can new rows be checked automatically?
More in Sheets & data
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