email-safe-gaurd
v1.0.6
Published
A simple, fast, and robust email verification library for Node.js.
Readme
email-safe-gaurd
A simple, fast, and robust email verification library for Node.js.
Getting Started
Follow these instructions to get a copy of the project up and running on your local machine for development and testing purposes.
Prerequisites
You will need to have Node.js installed on your machine.
Usage
The primary function for verifying an email is EmailVerifier.verify().
Import the class: First, import the
EmailVerifierclass from theemail-safe-gaurdpackage.import { EmailVerifier } from 'email-safe-gaurd';Call the
verifymethod: Theverifymethod is anasyncstatic method on theEmailVerifierclass. You need to pass the email address you want to check as a string.const emailToCheck = "[email protected]"; const result = await EmailVerifier.verify(emailToCheck);
Understanding the Result
The verify method returns a Promise that resolves to an object with the following structure:
isValid(boolean):trueif the email is valid, otherwisefalse.reason(string, optional): IfisValidisfalse, this field will contain the reason for the failure.
Possible failure reasons are:
"INVALID_INPUT": The input was not a string or was empty."INVALID_SYNTAX": The email address does not conform to standard syntax."DISPOSABLE_DOMAIN": The email domain is from a known disposable email provider."NO_MX_RECORDS": The domain does not have valid MX (Mail Exchange) records.
Example
Here is a complete example of how to use the function and handle the result:
import { EmailVerifier } from 'email-safe-gaurd';
async function checkEmail(email) {
const result = await EmailVerifier.verify(email);
if (result.isValid) {
console.log(`✅ Email "${email}" is valid.`);
} else {
console.log(`❌ Email "${email}" is invalid. Reason: ${result.reason}`);
}
}
// --- Try it out ---
checkEmail("[email protected]");
checkEmail("[email protected]");
checkEmail("[email protected]");