How to validate email addresses in OCaml

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

 

Validate e-mail in OCaml


open Cohttp_lwt_unix
open Cohttp
open Lwt

let uri = Uri.of_string "https://mailcheck.p.rapidapi.com/?domain=EMAIL-OR-DOMAIN" in
let headers = Header.add_list (Header.init ()) [
	("x-rapidapi-host", "mailcheck.p.rapidapi.com");
	("x-rapidapi-key", "YOUR-API-KEY");
] in

Client.call ~headers `GET uri
>>= fun (res, body_stream) ->
(* Do stuff with the result *)
                

 

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

 

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": "imailto.net",
    "text": "Suspicious e-mail",
    "reason": "Heuristics (x2a)",
    "risk": 91,
    "mx_host": "mail.imailto.net",
    "mx_info": "Using MX pointer mail.imailto.net from DNS with priority: 0",
    "mx_ip": "89.38.99.80",
    "last_changed_at": "2020-06-11T09:56:02+02:00"
}
               

 

This will tell you if you should block the domain imailto.net 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!