Tutorial: How to Use an Email Verification API with Java

Using an API for email verification involves sending a GET request to the API endpoint. Here's how you can do this using Java:

                        
import org.json.JSONArray;
import org.json.JSONObject;

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;

public class Main {

    private static final String API_KEY = "YOUR_API_KEY";
    private static final String EMAIL = "Email_Address";

    public static void main(String[] args) {
        try {
            URL url = new URL("https://api.ValidEmail.net/?email=" + EMAIL + "&token=" + API_KEY);
            HttpURLConnection conn = (HttpURLConnection) url.openConnection();
            conn.setRequestMethod("GET");
            conn.setRequestProperty("Accept", "application/json");

            if (conn.getResponseCode() != 200) {
                throw new RuntimeException("Failed : HTTP error code : " + conn.getResponseCode());
            }

            BufferedReader br = new BufferedReader(new InputStreamReader((conn.getInputStream())));

            String output;
            StringBuilder response = new StringBuilder();
            while ((output = br.readLine()) != null) {
                response.append(output);
            }

            conn.disconnect();

            JSONObject jsonObject = new JSONObject(response.toString());
            boolean isValid = jsonObject.getBoolean("IsValid");
            int score = jsonObject.getInt("Score");
            String email = jsonObject.getString("Email");
            String state = jsonObject.getString("State");
            String reason = jsonObject.getString("Reason");

            System.out.println("Email is valid: " + isValid);
            System.out.println("Score: " + score);
            System.out.println("Email state: " + state);
            System.out.println("Reason: " + reason);

            JSONArray additionalInfo = jsonObject.getJSONArray("EmailAdditionalInfo");
            for (int i = 0; i < additionalInfo.length(); i++) {
                JSONObject info = additionalInfo.getJSONObject(i);
                String key = info.getString("Key");
                String value = info.getString("Value");
                System.out.println(key + ": " + value);
            }

        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
                    

Remember to replace 'Email_Address' and 'YOUR_API_KEY' with the actual email address you want to verify and your actual API key.