generated from tpl/purs
fix: smtp timeout
This commit is contained in:
parent
425d797d8c
commit
ef0191e573
@ -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)
|
||||
|
Loading…
Reference in New Issue
Block a user