π§ 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: "PRIVATE_TOKEN_HERE" });
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: "PRIVATE_TOKEN_HERE",
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
| Rule | Default | Premium | Description |
|---|---|---|---|
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
| Parameter | Type | Required | Description |
|---|---|---|---|
apiKey | String | β | Your Dymo API key |
rules | Rules | β | 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.