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 hash containing the validation result and email intelligence data.
require 'net/http'
require 'json'
module Autheona
def self.validate_email(email, api_key, custom_policy = nil)
normalized_email = email.strip.downcase
payload = { email_address: normalized_email }
payload[:custom_policy] = custom_policy if custom_policy
uri = URI('https://api.autheona.com/v1/intelligence')
http = Net::HTTP.new(uri.host, uri.port)
http.use_ssl = true
request = Net::HTTP::Post.new(uri)
request['Content-Type'] = 'application/json'
request['x-api-key'] = api_key
request.body = payload.to_json
response = http.request(request)
raise "HTTP #{response.code}" unless response.is_a?(Net::HTTPSuccess)
JSON.parse(response.body)
end
end
Usage
Require the module, provide your API key via environment variable, and call validate_email with an email address. The function returns a hash with action field ('allow', 'block', or 'ignore') and detailed email analysis. For testing specific rules, pass a custom policy as the third argument.
require_relative 'autheona'
api_key = ENV['AUTHEONA_API_KEY']
# Basic validation
result = Autheona.validate_email('user@example.com', api_key)
puts 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 = Autheona.validate_email('user@tempmail.com', api_key, custom_policy)
puts 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: