mirror of
https://github.com/tiennm99/old-free-domains.git
synced 2026-10-15 16:15:05 +00:00
Update index.js
This commit is contained in:
1 parent
c69e790329
commit
46efb9ba07
1 file changed
+33
-37
@@ -5,45 +5,41 @@ const util = require("util");
|
||||
const argv = minimist(process.argv.slice(2));
|
||||
|
||||
async function validate() {
|
||||
const email = argv.email;
|
||||
|
||||
if(!email) return throw new Error("No email provided!");
|
||||
|
||||
const domain = email.split("@").pop();
|
||||
|
||||
const validEmail = validateEmail(email);
|
||||
|
||||
if(!validEmail) return throw new Error("The email address does not match the correct format!");
|
||||
|
||||
const getMXRecords = util.promisify(dns.resolveMx);
|
||||
let mxRecords = [];
|
||||
|
||||
try {
|
||||
const email = argv.email;
|
||||
|
||||
if(!email) return throw new Error("No email provided!");
|
||||
|
||||
const domain = email.split("@").pop();
|
||||
|
||||
const validEmail = validateEmail(email);
|
||||
|
||||
if(!validEmail) return throw new Error("The email address does not match the correct format!");
|
||||
|
||||
const getMXRecords = util.promisify(dns.resolveMx);
|
||||
let mxRecords = [];
|
||||
|
||||
try {
|
||||
mxRecords = await getMXRecords(domain);
|
||||
} catch (err) {
|
||||
throw new Error(`Error fetching MX records for the domain ${domain}: ${err.message}`);
|
||||
}
|
||||
|
||||
if(!mxRecords.length) return throw new Error(`No MX records exist for the domain ${domain}!`);
|
||||
|
||||
const result = {
|
||||
"success": true,
|
||||
"email": email,
|
||||
"test_results": {
|
||||
"matches_format": true,
|
||||
"mx_exists": true
|
||||
},
|
||||
"results": {
|
||||
"domain": domain,
|
||||
"mx_records": mxRecords
|
||||
}
|
||||
}
|
||||
|
||||
console.log(result);
|
||||
} catch(err) {
|
||||
throw new Error(err.message);
|
||||
mxRecords = await getMXRecords(domain);
|
||||
} catch (err) {
|
||||
throw new Error(`Error fetching MX records for the domain ${domain}: ${err.message}`);
|
||||
}
|
||||
|
||||
if(!mxRecords.length) return throw new Error(`No MX records exist for the domain ${domain}!`);
|
||||
|
||||
const result = {
|
||||
"success": true,
|
||||
"email": email,
|
||||
"test_results": {
|
||||
"matches_format": true,
|
||||
"mx_exists": true
|
||||
},
|
||||
"results": {
|
||||
"domain": domain,
|
||||
"mx_records": mxRecords
|
||||
}
|
||||
}
|
||||
|
||||
console.log(result);
|
||||
}
|
||||
|
||||
validate();
|
||||
|
||||
Reference in new issue
Block a user