πŸ“§ Email Validation in Zod

Easily validate emails in your project with Dymo API integrated with Zod.

A better, simpler way to validate emails with Dymo API + Zod in a single line of code!

About Email Validation

What is Email Validation?

Email validation uses Dymo API to check for fraud, invalid addresses, MX records, and more. All async validations require parseAsync().

Usage

To start validating emails in your project with Zod, create a schema using dymoClient.emailSchema():

import { z } from "zod";
import DymoAPIZod from "@dymo-api/zod";

const dymoClient = new DymoAPIZod({ apiKey: "" });

const userSchema = z.object({
    email: dymoClient.emailSchema(),
    username: z.string().min(3),
    age: z.number().int().min(0)
});

Validating Data

(async () => {
    const validatedUser = await userSchema.parseAsync({
        email: "[email protected]",
        username: "build",
        age: 10
    });

    console.log(validatedUser);
    /*
    {
      email: "[email protected]", // normalized by Dymo API
      username: "build",
      age: 10
    }
    */
})();

Handling Invalid Emails

The schema will automatically throw an error if the email is fraudulent or invalid:

try {
    await userSchema.parseAsync({
        email: "[email protected]",
        username: "build",
        age: 10
    });
} catch (err) {
    console.error("Validation failed:", err.errors);
    /*
    [
        { path: ["email"], message: "Invalid email" }
    ]
    */
}

Optional Flags (for direct plugin-style usage)

You can pass options when creating the DymoAPIZod instance to customize behavior:

const dymoClient = new DymoAPIZod({
    apiKey: "",
    rules: {
        email: {
            deny: ["FRAUD", "INVALID", "NO_MX_RECORDS", "NO_REPLY_EMAIL"]
        }
    }
});
  • rules: Customize which email rules to apply.
  • parseAsync() must be used because the validator queries the Dymo API.

Examples with Other Validators

You can also create schemas for IPs, phones, and passwords:

const userSchema = z.object({
    email: dymoClient.emailSchema(),
    ip: dymoClient.ipSchema(),
    phone: dymoClient.phoneSchema(),

    // Coming Soon.
    password: dymoClient.passwordSchema()
});

Important: All async validators require parseAsync() because they make API requests.


Email Rules

RuleDefaultPremiumDescription
FRAUDβœ…βŒEmail flagged as fraudulent
INVALIDβœ…βŒInvalid email format
NO_MX_RECORDSβœ…βœ…Check for MX records
PROXIED_EMAIL❌❌Detect emails using proxy
FREE_SUBDOMAIN❌❌Emails from free subdomains
PERSONAL_EMAIL❌❌Detect personal vs corporate emails
CORPORATE_EMAIL❌❌Corporate email verification
NO_REPLY_EMAILβœ…βŒDetect no-reply addresses
ROLE_ACCOUNT❌❌Role-based email detection
NO_GRAVATARβŒβœ…Detect missing Gravatar profile
NO_REACHABLEβŒβœ…Check if email is reachable
HIGH_RISK_SCOREβŒβœ…High risk email score

Parameters

ParameterTypeRequiredDescription
apiKeyStringβœ…Your Dymo API key
rulesRules❌Customize which rules to apply
parseAsync()Functionβœ…Must be called to validate async IP rules

πŸ’‘ Tip: Using DymoAPIZod with Zod lets you combine real-time fraud checks with normal Zod validations in a single schema for secure, consistent, and easy-to-maintain validation.