fix(email-validator): improve MX record validation and update project configuration
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user