How to validate email addresses in Java

Our free API to validate e-mail addresses is really easy to use in Java

 

Verify e-mail in Java with OkHttp


OkHttpClient client = new OkHttpClient();

Request request = new Request.Builder()
	.url("https://mailcheck.p.rapidapi.com/?domain=EMAIL-OR-DOMAIN")
	.get()
	.addHeader("x-rapidapi-host", "mailcheck.p.rapidapi.com")
	.addHeader("x-rapidapi-key", "YOUR-API-KEY")
	.build();

Response response = client.newCall(request).execute();
                

 

This will return a JSON-array with information about the domain, and if you should block it or not.

 

For example, say you want to verify the e-mail address whatever@ethereum1.top, to see if you should allow that e-mail to register an account, or sign up for your newsletter.

Your code would look something like this, this time using the Unirest object:

 

Verify e-mail in Java with Unirest


HttpResponse<String> response = Unirest.get("https://mailcheck.p.rapidapi.com/?domain=whatever@ethereum1.top")
	.header("x-rapidapi-host", "mailcheck.p.rapidapi.com")
	.header("x-rapidapi-key", "YOUR-API-KEY")
	.asString();
                

 

You can of course just send it as a regular GET-request to that URL also, in your favorite way, as long as you have the API-key in the header.

You will receive a JSON response, telling you if this is a disposable e-mail to block, or if there are other issues with the domain:

 


{
   "valid": true,
   "block": true,
   "disposable": true,
   "domain": "ethereum1.top",
   "text": "Disposable e-mail",
   "reason": "Heuristics (1b)",
   "risk": 91,
   "mx_host": "mail56.ethereum1.top",
   "mx_info": "Unable to connect to MX on port 25",
   "mx_ip": "109.236.84.18",
   "last_changed_at": "2020-06-11T09:56:02+02:00"
}
               

 

This will tell you if you should block the domain ethereum1.top or not, and the reason to why the API thinks so (disposable e-mail, etc). You can also see more detailed documentation of the response here.

To get started for free, and get an API key, click here!