fix(email-validator): improve MX record validation and update project configuration

This commit is contained in:
2026-04-30 07:41:08 +00:00
parent 0885b139e9
commit 705ef9ce71
12 changed files with 2147 additions and 4153 deletions
@@ -101,7 +101,12 @@ export class EmailAddressValidator {
}
}
const result = await this.smartdns.getRecords(domain, 'MX');
let result: any;
try {
result = await this.smartdns.getRecords(domain, 'MX');
} finally {
this.smartdns.destroy();
}
if (this.options.cacheDnsResults) {
this.dnsCache.set(domain, { result, timestamp: Date.now() });
@@ -124,10 +129,7 @@ export class EmailAddressValidator {
// Extract exchange values from MX records
return mxRecords.map((record: any) => {
if (record && record.exchange) {
return record.exchange;
}
return '';
return record?.value || record?.exchange || '';
}).filter(Boolean);
}
@@ -221,9 +223,9 @@ export class EmailAddressValidator {
// Check MX records
const mxRecords = await this.checkMxRecords(domainPart);
result.mxValid = !!mxRecords;
result.mxValid = Array.isArray(mxRecords) && mxRecords.length > 0;
if (!mxRecords) {
if (!result.mxValid) {
result.reason = 'Domain does not have valid MX records';
return result;
}