39 lines
1.2 KiB
JavaScript
39 lines
1.2 KiB
JavaScript
import handleNodemailer from "../../backend/handleNodemailer";
|
|
import emailMxLookup from "../verification/email-mx-lookup";
|
|
import emailRegexCheck from "../verification/email-regex-test";
|
|
export default async function validateEmail({ email, welcomeEmailOptions, }) {
|
|
var _a;
|
|
if (!email) {
|
|
return {
|
|
isValid: false,
|
|
message: "Email is required.",
|
|
};
|
|
}
|
|
if (!emailRegexCheck(email)) {
|
|
return {
|
|
isValid: false,
|
|
message: "Invalid email format.",
|
|
};
|
|
}
|
|
const checkEmailMxRecords = await emailMxLookup(email);
|
|
if (!checkEmailMxRecords) {
|
|
return {
|
|
isValid: false,
|
|
message: "Email domain does not have valid MX records.",
|
|
};
|
|
}
|
|
if (welcomeEmailOptions) {
|
|
const welcomeEmail = await handleNodemailer(welcomeEmailOptions);
|
|
if (!((_a = welcomeEmail === null || welcomeEmail === void 0 ? void 0 : welcomeEmail.accepted) === null || _a === void 0 ? void 0 : _a[0])) {
|
|
return {
|
|
isValid: false,
|
|
message: "Email verification failed.",
|
|
};
|
|
}
|
|
}
|
|
return {
|
|
isValid: true,
|
|
message: "Email is valid.",
|
|
};
|
|
}
|