Skip to content

valarpirai/disposable-emails-validator-java

Repository files navigation

Disposable email domain validator

Why?

Use it to validate email addresses during sign-up, or simply to determine the number of real email addresses in your system.

<repository>
  <id>github</id>
  <name>GitHub Packages</name>
  <url>https://<github_user>:<github_personal_access_token>@maven.pkg.github.com/valarpirai/disposable-emails-validator-java</url>
</repository>
<dependency>
  <groupId>org.valarpirai</groupId>
  <artifactId>disposable-email</artifactId>
  <version>{version}</version>
</dependency>

Usage

We are using an autogenerated list which is updated every 24 hours - https://github.com/disposable/disposable

Getting the latest Domain list

This lib has a list of disposable email domains (encoded file) inside resources. The following method will download latest disposable email list from here and use it Note: In your application startup, you need to call this method to fetch the updated domain list.

DisposableEmail.refreshDisposableDomains()

Get DNS and disposable details of an email domain. Response DomainDetails

domainDetails = DisposableEmail.getDomainDetails("gmail.com")

domainDetails.disposableDomain -> false
domainDetails.mxRecordPresent -> true
domainDetails = DisposableEmail.getDomainDetails("yopmail.com")

domainDetails.disposableDomain -> true
domainDetails.mxRecordPresent -> true
domainDetails = DisposableEmail.getDomainDetails("nonexisting123.com")

domainDetails.disposableDomain -> false
domainDetails.mxRecordPresent -> false

Check whether a given email address is disposable address (local check)

DisposableEmail.isDisposable("hello@gmail.com") -> false
DisposableEmail.isDisposable("hello@mailsac.com") -> true

Disposable domain with valid DNS MX Record

DisposableEmail.hasValidMailDomain("hello@mailsac.com") -> true

Valid domain without DNS MX Record

DisposableEmail.hasValidMailDomain("god.com") -> false

Use a different DNS resolver

DisposableEmail.hasValidMailDomain("hello@gmail.com", DnsResolverType.CLOUD_FLARE) -> true
DisposableEmail.hasValidMailDomain("hello@gmail.com", DnsResolverType.GOOGLE) -> true

Whitelist Domains

DisposableEmail.addDomainToWhitelist("mailsac.com")
DisposableEmail.isDisposable("hello@mailsac.com") -> false

DisposableEmail.removeDomainFromWhitelist("mailsac.com")
DisposableEmail.isDisposable("mailsac.com") -> true

Blacklist Domains

DisposableEmail.addDomainToBlacklist("gmail.com")
DisposableEmail.isDisposable("hello@gmail.com") -> true

DisposableEmail.removeDomainFromBlacklist("gmail.com")
DisposableEmail.isDisposable("gmail.com") -> true

How does it work?

  • We are using BloomFilter, a space-efficient probabilistic data structure, to store a list of Disposable email domains
    • This will work in offline mode.
  • We are using DNS over HTTPS (DoH) to verify the MX Records
    • CloudFlare (1.1.1.1) and Google(dns.google) DNS resolvers are support
    • This will work in online mode. requires an internet connection

Packages

 
 
 

Languages