Bird

Verify an email address with Node.js

Send a verification code to your own email address, enter it in the terminal and inspect the check result.

1. Prepare the workspace

Create a Bird API key and use an email address you control. Email verification uses the shared Bird Verify sender, so this first test does not require your own sending domain. The first-verification guide covers account setup and channel choices.

2. Install and configure

Use Node.js 20.3 or later. In a new project directory:
Code example
npm init -y
npm install @messagebird/sdk tsx
export BIRD_API_KEY="YOUR_API_KEY"
export BIRD_TEST_EMAIL="YOUR_EMAIL_ADDRESS"
Replace the environment values with your own workspace credentials and test destination. The SDK selects the API region from the key. Run this example on your server or development machine.

3. Run the example

Save as verify.mts:
Code example
import { BirdClient } from "@messagebird/sdk";
import { createInterface } from "node:readline/promises";
import { stdin as input, stdout as output } from "node:process";

const apiKey = process.env.BIRD_API_KEY;
if (!apiKey) throw new Error("Set BIRD_API_KEY before running the sample.");
const bird = new BirdClient({ apiKey });

const email = process.env.BIRD_TEST_EMAIL;
if (!email) throw new Error("Set BIRD_TEST_EMAIL to your email address.");
const verification = await bird.verify.verifications.create({ to: { email } });
console.log(verification.id, verification.status);
const terminal = createInterface({ input, output });
try {
  const code = (await terminal.question("Enter the code from your email: ")).trim();
  const result = await bird.verify.verifications.check({ to: { email }, code });
  console.log("Verified:", result.success);
} finally {
  terminal.close();
}
Code example
npx tsx verify.mts

4. Inspect the outcome

The first call prints the verification ID and status. After you enter the received code, the check prints whether it succeeded. A delivered code alone does not verify the address; use the check result.
In an application, bind the intended destination and customer action to the server session. The SDK check accepts the destination and code, so do not let an untrusted browser substitute a different destination when checking. Follow signup and recovery for that complete application flow.

Next steps