62 lines
1.8 KiB
TypeScript
62 lines
1.8 KiB
TypeScript
|
|
export interface IEmailValidationResult {
|
||
|
|
isValid: boolean;
|
||
|
|
hasMx: boolean;
|
||
|
|
hasSpamMarkings: boolean;
|
||
|
|
score: number;
|
||
|
|
details?: {
|
||
|
|
formatValid?: boolean;
|
||
|
|
mxRecords?: string[];
|
||
|
|
disposable?: boolean;
|
||
|
|
role?: boolean;
|
||
|
|
spamIndicators?: string[];
|
||
|
|
errorMessage?: string;
|
||
|
|
};
|
||
|
|
}
|
||
|
|
/**
|
||
|
|
* Advanced email validator class using smartmail's capabilities
|
||
|
|
*/
|
||
|
|
export declare class EmailValidator {
|
||
|
|
private validator;
|
||
|
|
private dnsCache;
|
||
|
|
constructor(options?: {
|
||
|
|
maxCacheSize?: number;
|
||
|
|
cacheTTL?: number;
|
||
|
|
});
|
||
|
|
/**
|
||
|
|
* Validates an email address using comprehensive checks
|
||
|
|
* @param email The email to validate
|
||
|
|
* @param options Validation options
|
||
|
|
* @returns Validation result with details
|
||
|
|
*/
|
||
|
|
validate(email: string, options?: {
|
||
|
|
checkMx?: boolean;
|
||
|
|
checkDisposable?: boolean;
|
||
|
|
checkRole?: boolean;
|
||
|
|
checkSyntaxOnly?: boolean;
|
||
|
|
}): Promise<IEmailValidationResult>;
|
||
|
|
/**
|
||
|
|
* Gets MX records for a domain with caching
|
||
|
|
* @param domain Domain to check
|
||
|
|
* @returns Array of MX records
|
||
|
|
*/
|
||
|
|
private getMxRecords;
|
||
|
|
/**
|
||
|
|
* Validates multiple email addresses in batch
|
||
|
|
* @param emails Array of emails to validate
|
||
|
|
* @param options Validation options
|
||
|
|
* @returns Object with email addresses as keys and validation results as values
|
||
|
|
*/
|
||
|
|
validateBatch(emails: string[], options?: {
|
||
|
|
checkMx?: boolean;
|
||
|
|
checkDisposable?: boolean;
|
||
|
|
checkRole?: boolean;
|
||
|
|
checkSyntaxOnly?: boolean;
|
||
|
|
}): Promise<Record<string, IEmailValidationResult>>;
|
||
|
|
/**
|
||
|
|
* Quick check if an email format is valid (synchronous, no DNS checks)
|
||
|
|
* @param email Email to check
|
||
|
|
* @returns Boolean indicating if format is valid
|
||
|
|
*/
|
||
|
|
isValidFormat(email: string): boolean;
|
||
|
|
}
|