Prerequisites
Before using this code, you need:
- An Autheona account: Sign up at https://app.autheona.com/sign-up
- A project (Sandbox or Production): See project creation guide
- An access token with API permissions: See access token documentation
Store your access token securely using environment variables. Never hardcode tokens in your source code.
Code
This function sends an HTTP POST request to the Autheona API with the email address to validate. It accepts an optional customPolicy parameter for testing validation rules. The function returns the API response as JSON containing the validation result and email intelligence data.
import java.io.*;
import java.net.*;
import java.nio.charset.StandardCharsets;
public class AutheonaClient {
public static String validateEmail(String email, String apiKey, String customPolicy) throws IOException {
String normalizedEmail = email.trim().toLowerCase();
StringBuilder payload = new StringBuilder();
payload.append("{\"email_address\":\"").append(normalizedEmail).append("\"}");
if (customPolicy != null) {
payload = new StringBuilder();
payload.append("{\"email_address\":\"").append(normalizedEmail).append("\",");
payload.append("\"custom_policy\":").append(customPolicy).append("}");
}
URL url = new URL("https://api.autheona.com/v1/intelligence");
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setRequestMethod("POST");
conn.setRequestProperty("Content-Type", "application/json");
conn.setRequestProperty("x-api-key", apiKey);
conn.setDoOutput(true);
try (OutputStream os = conn.getOutputStream()) {
byte[] input = payload.toString().getBytes(StandardCharsets.UTF_8);
os.write(input, 0, input.length);
}
int responseCode = conn.getResponseCode();
if (responseCode != 200) {
throw new IOException("HTTP " + responseCode);
}
try (BufferedReader br = new BufferedReader(
new InputStreamReader(conn.getInputStream(), StandardCharsets.UTF_8))) {
StringBuilder response = new StringBuilder();
String line;
while ((line = br.readLine()) != null) {
response.append(line);
}
return response.toString();
}
}
}
Usage
Import the class, provide your API key via environment variable, and call validateEmail with an email address. The function returns a JSON string with action field ('allow', 'block', or 'ignore') and detailed email analysis. For testing specific rules, pass a custom policy as the third argument.
public class Main {
public static void main(String[] args) {
String apiKey = System.getenv("AUTHEONA_API_KEY");
try {
// Basic validation
String result = AutheonaClient.validateEmail("user@example.com", apiKey, null);
System.out.println(result);
// With custom policy for testing
String customPolicy = "{" +
"\"parent_rules\":[" +
"{\"action\":\"block\",\"field\":\"domain_disposable\",\"operator\":\"==\",\"target\":{\"bool\":true}}" +
"]," +
"\"stop_on_block\":true," +
"\"version\":\"1.0\"" +
"}";
String testResult = AutheonaClient.validateEmail("user@tempmail.com", apiKey, customPolicy);
System.out.println(testResult);
} catch (IOException e) {
e.printStackTrace();
}
}
}
Custom Policy Parameter
Warning
The custom_policy parameter is for testing only. In production, configure policies using the Policy Editor instead of sending them in requests.
Add custom_policy to your request body to test custom validation rules:
String customPolicy = "{" +
"\"parent_rules\":[" +
"{\"action\":\"block\",\"field\":\"domain_disposable\",\"operator\":\"==\",\"target\":{\"bool\":true}}," +
"{\"action\":\"block\",\"field\":\"email_deliverable\",\"operator\":\"==\",\"target\":{\"bool\":false}}," +
"{\"action\":\"ignore\",\"field\":\"domain_free\",\"operator\":\"==\",\"target\":{\"bool\":true}}" +
"]," +
"\"stop_on_block\":true," +
"\"version\":\"1.0\"" +
"}";
Available fields: domain_disposable, domain_free, email_deliverable, domain_has_website, email_has_fraud_pattern, and more from the API response.
Environment Variables
Set your API key as an environment variable to keep it out of your code:
export AUTHEONA_API_KEY="your-api-key"
Note
This is a minimal integration example. For production use cases, error handling, retry logic, rate limiting, and advanced response processing, refer to the API Reference Documentation.
Support
For issues with the API, refer to: