Last active
May 8, 2024 11:57
-
-
Save Igloczek/7bfc459109f4a01f7e046b591d2a842a to your computer and use it in GitHub Desktop.
Simple way to filter out most of the disposable / temporary emails
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import TTLCache from "@isaacs/ttlcache" | |
import axios from "axios" | |
const domainsCache = new TTLCache({ | |
ttl: 1000 * 60 * 60 * 24, // cache for 24h | |
}) | |
const lists = [ | |
"https://raw.githubusercontent.com/wesbos/burner-email-providers/master/emails.txt", // submiting my findings here | |
"https://raw.githubusercontent.com/Igloczek/burner-email-providers/master/emails.txt", // adding my fork, as sometime PRs are stuck unmerged | |
"https://raw.githubusercontent.com/7c/fakefilter/main/txt/data.txt", | |
"https://raw.githubusercontent.com/unkn0w/disposable-email-domain-list/main/domains.txt", | |
"https://raw.githubusercontent.com/disposable/disposable-email-domains/master/domains_strict.txt", | |
"https://raw.githubusercontent.com/disposable-email-domains/disposable-email-domains/master/disposable_email_blocklist.conf", | |
] | |
async function loadDomains() { | |
const cached = domainsCache.get("domains") | |
if (cached) { | |
return cached | |
} | |
const domains = new Set() | |
await Promise.allSettled( | |
lists.map(async (list) => { | |
const response = await axios.get(list) | |
response.data.split("\n").forEach((item) => { | |
const line = item.trim() | |
if (line !== "" && !line.startsWith("#")) { | |
domains.add(line) | |
} | |
}) | |
}), | |
) | |
domainsCache.set("domains", domains) | |
return domains | |
} | |
// warm up the cache | |
await loadDomains() | |
// import this function whenever you need to check user email, for example before creating an account | |
export async function verifyEmail(email) { | |
const domains = await loadDomains() | |
return !domains.has(email.split("@")[1]) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment