How to Validate an Email Address using Java

2 min readMay 11, 2022


If your app is storing contact info, it’s important to make sure that info is entered correctly, or you might end up with a messy problem to solve later. With the help of our Email Validation API, your app can out if an address is syntactically correct, identify the relevant mail server (if it exists), and contact the email server without sending any actual emails. You can include this API in your project easily by following instructions included below for Java.

First install the Java SDK with Maven. To begin, add a reference to the repository in pom.xml:


Next up, add one to the dependency:


Finally, include the import classes and then copy the below code examples to call the validation API:

// Import classes:
//import com.cloudmersive.client.invoker.ApiClient;
//import com.cloudmersive.client.invoker.ApiException;
//import com.cloudmersive.client.invoker.Configuration;
//import com.cloudmersive.client.invoker.auth.*;
//import com.cloudmersive.client.EmailApi;
ApiClient defaultClient = Configuration.getDefaultApiClient();// Configure API key authorization: Apikey
ApiKeyAuth Apikey = (ApiKeyAuth) defaultClient.getAuthentication("Apikey");
Apikey.setApiKey("YOUR API KEY");
// Uncomment the following line to set a prefix for the API key, e.g. "Token" (defaults to null)
EmailApi apiInstance = new EmailApi();
String email = "email_example"; // String | Email address to validate, e.g. \"\". The input is a string so be sure to enclose it in double-quotes.
try {
FullEmailValidationResponse result = apiInstance.emailFullValidation(email);
} catch (ApiException e) {
System.err.println("Exception when calling EmailApi#emailFullValidation");

Just like that, you’re all done — easy as pie. If this is your first time using a Cloudmersive API, don’t forget to head to our website and register for a free account to receive a Cloudmersive API key.




There’s an API for that. Cloudmersive is a leader in Highly Scalable Cloud APIs.