Show HN: I built a deep email validation library in Kotlin

github.com

3 points by mbalatsko a day ago

Show HN: I built a deep email validation library to learn Kotlin

Hey HN,

I wanted a real-world project to properly learn Kotlin (coroutines, DSLs, etc.) and decided to tackle a problem I've found surprisingly underserved: comprehensive email validation. Most solutions stop at regex, but that doesn't prevent sign-ups from user@notarealdomain.com or disposable email services.

So, I built a library that performs a series of deeper checks. I just tagged the v1.0.0 release because the API is now stable and I think it's ready for feedback from the community.

It validates an email in layers:

1. Syntax: A robust check that's more reliable than a typical regex.

2. Domain Registrability: Checks the domain against the Public Suffix List to ensure it's on a real TLD.

3. MX Records: A DNS query to see if the domain is actually configured to receive email.

4. Disposable Services: Checks against a list of known temporary/throwaway email providers.

5. SMTP Connection (Optional): A live check to see if the mailbox actually exists. This is off by default since port 25 is often blocked, but can be enabled via a proxy.

One of my main goals was to build something that would be useful on both the server and on a client like an Android app. This led to a couple of key design decisions:

- It's built with coroutines for non-blocking, concurrent I/O.

- It has a full offline mode. You can disable all network checks and run it using bundled datasets for things like syntax and disposable domain checks, which is great for providing instant, client-side feedback.

The configuration is done through a simple Kotlin DSL.

The project is MIT licensed. I'm posting this to get your thoughts on the approach, the architecture, or any Kotlin idioms I might have missed. How do you all typically handle this problem beyond regex?

GitHub: https://github.com/mbalatsko/emailverifier-kt