An email address can look right but still be wrong. Real email uses in depths address validation to check if emails really exist without sending any messages.
You can use a regular expression or email_validator to check if an email address is formatted correctly. For example using in python.
pattern_regex_test.pyimport reif re.match(r"[^@]+@[^@]+\.[^@]+", "foo@bar.com"):print("address is valid")else:print("not valid")
To check if an address really exists you can use the Real Email API which does in depth email address inspection on the email server. In this example we use the python requests library.
real_email_validation.pyimport requestsemail_address = "foo@bar.com"response = requests.get("https://isitarealemail.com/api/email/validate",params = {'email': email_address})status = response.json()['status']if status == "valid":print("email is valid")elif status == "invalid":print("email is invalid")else:print("email was unknown")
You will be able to test 100 emails per day for free. If you have more that that you will need to signup and get an API key. An email might be 'unknown' if the email server is unresponsive.
With an API key you wont be limited by how many addresses you can check. In python the example changes to add the API key.
real_email_validation_with_key.pyimport requestsapi_key = "" // todo put your api key hereemail_address = "foo@bar.com"response = requests.get("https://isitarealemail.com/api/email/validate",params = {'email': email_address},headers = {'Authorization': "Bearer " + api_key })status = response.json()['status']if status == "valid":print("email is valid")elif status == "invalid":print("email is invalid")else:print("email was unknown")
Depending on your use case you may like to use bulk csv file validation and read the csv file with python. This is better if you have one big list of emails to check rather than an on going process. First upload your csv file to Real Email, when it is validated you can read the result file with python like below.
import csvwith open('emails-validated.csv') as csvfile:reader = csv.DictReader(csvfile)for row in reader:print(row)# {'email': 'foo@bar.com', 'status': 'valid'}
Get started with real email validations today.