fix: smtp timeout

This commit is contained in:
orion 2023-12-12 19:20:08 -06:00
parent 425d797d8c
commit ef0191e573
Signed by: orion
GPG Key ID: 6D4165AE4C928719

View File

@ -1,4 +1,35 @@
import { checkEmail } from 'qed-mail'
import { checkSyntax, checkMX, checkSMTP } from 'qed-mail'
const DEFAULT_RESULT = {
reachable: false,
syntax: { valid: false },
mx: { valid: false },
smtp: { valid: false },
};
/** @type {(_: string) => Promise<import('qed-mail/src/types.js').Result>} */
async function checkEmail(email) {
const result = { email, ...DEFAULT_RESULT };
const syntax = checkSyntax(email);
if (!syntax.valid) {
return { ...result, syntax };
}
const mx = await checkMX(syntax.domain || '');
if (!mx.valid || !mx.mxRecords) {
return { ...result, syntax, mx };
}
const records = mx.mxRecords.sort((a, b) => a.priority - b.priority);
const smtp = await checkSMTP(email, records[0].exchange, 500);
if (!smtp.valid) {
return { ...result, syntax, mx, smtp };
}
return { ...result, reachable: true, syntax, mx, smtp };
}
/** @type {(_: string) => () => Promise<import('qed-mail/src/types.js').Result>} */
export const checkEmailImpl = s => () => checkEmail(s)