Skip to content

Instantly share code, notes, and snippets.

@Igloczek
Last active May 8, 2024 11:57
Show Gist options
  • Save Igloczek/7bfc459109f4a01f7e046b591d2a842a to your computer and use it in GitHub Desktop.
Save Igloczek/7bfc459109f4a01f7e046b591d2a842a to your computer and use it in GitHub Desktop.
Simple way to filter out most of the disposable / temporary emails
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