Using Python to validate emails and block temp mail
This document provides example python code to validate email addresses, block temp mail, and determine if they are from a disposable email provider using the Check-Mail API.
Check if an Email is Disposable using Python
Use the API endpoint to determine if an email address is disposable or valid.
Example Request:
import requests
url = "https://mailcheck.p.rapidapi.com/"
querystring = {"email":"sarah35@qualityth.com"}
headers = {
'x-rapidapi-host': "mailcheck.p.rapidapi.com",
'x-rapidapi-key': "YOUR-API-KEY"
}
response = requests.request("GET", url, headers=headers, params=querystring)
print(response.text)
Replace YOUR_API_KEY
with your actual API key and sarah35@qualityth.com
with the email address you want to validate in the example python code.
Example Response:
{
"valid": true,
"block": true,
"disposable": true,
"domain": "qualityth.com",
"text": "Disposable / temporary domain",
"reason": "Heuristics x2",
"risk": 93,
"mx_host": "mx-post.qualityth.com",
"possible_typo": [],
"mx_ip": "198.199.100.213",
"mx_info": "Using MX pointer mx-post.qualityth.com from DNS with priority: 21",
"last_changed_at":"2024-09-25T06:52:59+02:00"
}
Explanation
- The
valid
field indicates if the provided email address is in a valid format, and if the domain exists and accepts e-mails - The
block
field indicates if we suggest you should block this e-mail or domain in your systems. - The
disposable
field indicates whether the email address belongs to a disposable email provider.
Next Steps
- Integrate this code into your python code to automate the detection of disposable email addresses.
- Refer to the documentation for further details on the API.