Skip to content

preetampotdar/email-validator

Email Validator Application

Java CI with Gradle

Render

Overview

This Spring Boot application provides a REST API to validate email addresses. It checks for valid email syntax, disposable email domains, and MX DNS records.

Features

  • Validate email syntax using Apache Commons Validator.
  • Check if an email domain is disposable (e.g., mailinator.com).
  • Verify MX DNS records for email domains.
  • Caching of validation results using Caffeine for improved performance.
  • Health check endpoints for API and downstream services (DNS, cache).
  • Integration with Spring Boot Actuator for monitoring.

Technologies Used

  • Java 17+
  • Spring Boot 3.x
  • Spring Web
  • Spring Boot Actuator
  • Caffeine Cache
  • Apache Commons Validator
  • dnsjava (for DNS lookups)
  • JUnit 5 & Mockito (for testing)
  • Lombok

Getting Started

Prerequisites

  • Java 17 or higher installed
  • Maven or Gradle build tool
  • Internet connection (for DNS lookups)

Build and Run

./mvnw clean install
./mvnw spring-boot:run

or using Gradle:

./gradlew clean build
./gradlew bootRun

API Usage

Validate Email

Endpoint: POST /api/v1/email/validate

Request:

{
  "email": "user@example.com"
}

Response:

{
  "email": "user@example.com",
  "validSyntax": true,
  "isSafe": true,
  "mxResponse": {
    "hasMx": true
  },
  "isDisposable": false
}

Caching

Validation results are cached for 30 minutes using Caffeine Cache to reduce DNS queries and improve performance.

Health Checks

  • /actuator/health - Overall application health
  • /actuator/health/cache - Cache health indicator
  • /actuator/health/dns - DNS MX record health indicator

Testing

Unit tests cover the service logic, controller endpoints, cache behavior, and health indicators.

Run tests with:

./mvnw test

or

./gradlew test

Configuration

Application properties (e.g., cache settings) can be customized in src/main/resources/application.properties.

Example cache config:

spring.cache.cache-names=emailValidationCache
spring.cache.caffeine.spec=expireAfterWrite=30m,maximumSize=10000

Notes

  • The app relies on external DNS servers for MX record lookups; network issues may affect validation.
  • Disposable email domain list is hardcoded but can be extended or replaced with third-party services.

License

This project is licensed under the Apache License 2.0.


Created by Preetam Potdar

Releases

No releases published

Packages

No packages published

Contributors 2

  •  
  •