Skip to content

Instantly share code, notes, and snippets.

@someguy9
Created November 1, 2024 22:31
Show Gist options
  • Save someguy9/d3715246e91d55b6752f2c75fd81a986 to your computer and use it in GitHub Desktop.
Save someguy9/d3715246e91d55b6752f2c75fd81a986 to your computer and use it in GitHub Desktop.
// Function to check if an email is disposable using multiple API services
async function isDisposableEmail(email, ip = null) {
try {
// Construct API URLs with email and optionally IP for StopForumSpam
const debounceUrl = `https://disposable.debounce.io/?email=${email}`;
const verifyMailUrl = `https://verifymail.io/api/${email.split('@')[1]}?key=${process.env.VERIFYMAIL_API_KEY}`;
const stopForumSpamUrl = `https://api.stopforumspam.org/api?email=${email}&json=true${ip ? `&ip=${ip}` : ""}`;
// Make parallel requests to the APIs
const [debounceResponse, verifyMailResponse, stopForumSpamResponse] = await Promise.all([
fetch(debounceUrl),
fetch(verifyMailUrl),
fetch(stopForumSpamUrl)
]);
// Parse JSON responses
const [debounceData, verifyMailData, stopForumSpamData] = await Promise.all([
debounceResponse.json(),
verifyMailResponse.json(),
stopForumSpamResponse.json()
]);
// Check each API's response for disposable or spam indications
const isDisposable =
debounceData.disposable === "true" || // Check if Debounce API flags it as disposable
verifyMailData.disposable === true || // Check if VerifyMail API flags it as disposable
(
// Check StopForumSpam API for suspicious email and IP patterns
stopForumSpamData.success === 1 &&
(
(stopForumSpamData.email?.appears === 1 && stopForumSpamData.email?.confidence > 80) || // High confidence for email spam
(ip && stopForumSpamData.ip?.appears === 1 && stopForumSpamData.ip?.confidence > 80) || // High confidence for IP spam, only if IP is provided
(ip && stopForumSpamData.ip?.torexit === 1 && stopForumSpamData.ip?.confidence > 60) // Tor exit node with moderate confidence, only if IP is provided
)
);
return isDisposable;
} catch (error) {
console.error("Error verifying email:", error);
// Optional: Return true if you want to treat errors as potential disposables to be cautious
return false; // False indicates the email is considered non-disposable if an error occurs
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment