Validating an email address using an open-source Python library
To check whether the email address firstname.lastname@example.org is valid, we can just call the `validate_email` function with that email as the argument. A full implementation would look like this:
If the email address is invalid, `validate_email` throws an `EmailNotValidError`. In this case, however, the returned `valid_result` object will be of the form:
Drawbacks to using Python's open-source libraries for email validation
While this library provides a simple interface for validating emails, the information returned is fairly limited. This library only checks if the email syntax is correct and if the domain resolves without providing other descriptive information. Additionally, because invalid emails are handled as exceptions, invalid emails require a separate workflow from valid emails.
Validating emails in Python using Abstract's email validation API
There are a number of API's for email validation, although Abstract offers a free email validation API that offers a variety of additional information on validated email addresses. It also includes detailed documentation that covers how to use the API and the variety of information that it can provide.
Compared to the previous method of email validation, Abstract’s easy-to-use API provides more descriptive information about the email address being validated. For example, this API identifies whether emails are free or disposable and returns a quality score for all valid emails. This is similar to how IP geolocation API's can check if an IP address is using a VPN or proxy. This information can help you to more effectively analyze the emails contained within your database.
With the email validation API, we can easily check whether test@abstract_api.com is a valid email:
For the above request, we get a result of the following format: