How to Validate an Email Address using Java

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:

<repositories>
<repository>
<id>jitpack.io</id>
<url>https://jitpack.io</url>
</repository>
</repositories>

Next up, add one to the dependency:

<dependencies>
<dependency>
<groupId>com.github.Cloudmersive</groupId>
<artifactId>Cloudmersive.APIClient.Java</artifactId>
<version>v4.25</version>
</dependency>
</dependencies>

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)
//Apikey.setApiKeyPrefix("Token");
EmailApi apiInstance = new EmailApi();
String email = "email_example"; // String | Email address to validate, e.g. \"support@cloudmersive.com\". The input is a string so be sure to enclose it in double-quotes.
try {
FullEmailValidationResponse result = apiInstance.emailFullValidation(email);
System.out.println(result);
} catch (ApiException e) {
System.err.println("Exception when calling EmailApi#emailFullValidation");
e.printStackTrace();
}

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.

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

How to apply an HTML Template in C# .NET Framework

AWS VPC Network Configuration EIP + IGW + NAT Gateway

Python decorator: How it changes behaviour of other classes and functions

Python logo

Chain analytics launching on Hallar

What are code libraries.

10 free stock photos you would actually use (Sunday 29th 08PM edition)

Humans of DataHub: Hyejin Yoon

Integration of LVM with Hadoop-Cluster using AWS Cloud

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Cloudmersive

Cloudmersive

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

More from Medium

Launch Spring Batch job from a REST endpoint 🚀

Get Intelligence on an IP Address with Java

Fixing code style errors with Spotless and Maven

How to consume Restful web Service in a spring boot application