Prerequisites
Before using this code, you need:
- An Autheona account: Sign up at https://app.autheona.com/sign-up
- A project (Sandbox or Production): See project creation guide
- An access token with API permissions: See access token documentation
Store your access token securely using environment variables. Never hardcode tokens in your source code.
Code
This function sends an HTTP POST request to the Autheona API with the email address to validate. It accepts an optional custom_policy parameter for testing validation rules. The function returns the API response as a dict containing the validation result and email intelligence data.
import json
import os
from urllib import request, error
def validate_email(email: str, api_key: str, custom_policy: dict = None) -> dict:
normalized_email = email.strip().lower()
payload = {"email_address": normalized_email}
if custom_policy:
payload["custom_policy"] = custom_policy
data = json.dumps(payload).encode('utf-8')
req = request.Request(
'https://api.autheona.com/v1/intelligence',
data=data,
headers={
'Content-Type': 'application/json',
'x-api-key': api_key
},
method='POST'
)
try:
with request.urlopen(req) as response:
return json.loads(response.read().decode('utf-8'))
except error.HTTPError as e:
raise Exception(f'HTTP {e.code}')
Usage
Import the function, provide your API key via environment variable, and call validate_email with an email address. The function returns a dict with action field ('allow', 'block', or 'ignore') and detailed email analysis. For testing specific rules, pass a custom policy as the third argument.
import os
from autheona import validate_email
api_key = os.environ['AUTHEONA_API_KEY']
# Basic validation
result = validate_email('user@example.com', api_key)
print(result['action'])
# With custom policy for testing
custom_policy = {
'parent_rules': [
{'action': 'block', 'field': 'domain_disposable', 'operator': '==', 'target': {'bool': True}}
],
'stop_on_block': True,
'version': '1.0'
}
test_result = validate_email('user@tempmail.com', api_key, custom_policy)
print(test_result['action'])
Custom Policy Parameter
Warning
The custom_policy parameter is for testing only. In production, configure policies using the Policy Editor instead of sending them in requests.
Add custom_policy to your request body to test custom validation rules:
custom_policy = {
'parent_rules': [
{'action': 'block', 'field': 'domain_disposable', 'operator': '==', 'target': {'bool': True}},
{'action': 'block', 'field': 'email_deliverable', 'operator': '==', 'target': {'bool': False}},
{'action': 'ignore', 'field': 'domain_free', 'operator': '==', 'target': {'bool': True}}
],
'stop_on_block': True,
'version': '1.0'
}
Available fields: domain_disposable, domain_free, email_deliverable, domain_has_website, email_has_fraud_pattern, and more from the API response.
Environment Variables
Set your API key as an environment variable to keep it out of your code:
export AUTHEONA_API_KEY="your-api-key"
Note
This is a minimal integration example. For production use cases, error handling, retry logic, rate limiting, and advanced response processing, refer to the API Reference Documentation.
Support
For issues with the API, refer to: