Real-time email verification using only the Ruby standard library —
net/http and json.
Send a GET request with the email and your API token.
The helper below also handles interim Unknown results by waiting
RetryAfterSeconds and retrying automatically.
require 'net/http'
require 'json'
API_URL = 'https://api.validemail.net/'
API_KEY = 'YOUR_API_KEY' # find it in your ValidEmail dashboard
def verify_email(email, max_retries: 3)
result = nil
max_retries.times do
uri = URI(API_URL)
uri.query = URI.encode_www_form(email: email, token: API_KEY)
response = Net::HTTP.get_response(uri)
unless response.is_a?(Net::HTTPSuccess)
raise "Request failed with HTTP #{response.code}: #{response.body}"
end
result = JSON.parse(response.body)
# "Unknown" means the verification is still in progress (e.g. greylisting).
retry_after = result['RetryAfterSeconds']
if result['State'] == 'Unknown' && retry_after
sleep(retry_after)
next
end
return result
end
result # still pending after max_retries — treat as risky
end
result = verify_email('someone@example.com')
puts "Valid: #{result['IsValid']}"
puts "Score: #{result['Score']}"
puts "State: #{result['State']}"
puts "Reason: #{result['Reason']}"
puts 'Safe to send.' if result['IsValid'] && result['Score'] >= 80
State = "Unknown")
Some mail servers greylist first-time senders or respond slowly. Instead of failing, the API returns an
interim 200 OK result with State = "Unknown", a Reason of
PENDING or GREYLISTED, and a RetryAfterSeconds hint while the
verification finishes in the background.
RetryAfterSeconds seconds, then repeat the same request to get the final verdict.Unknown as "not yet decided" — never as a delivery failure.The balance endpoint is free to call and never consumes a credit — perfect for a pre-flight check before verifying a large list.
uri = URI('https://api.validemail.net/balance')
uri.query = URI.encode_www_form(token: API_KEY)
balance = JSON.parse(Net::HTTP.get(uri))['balance']
puts "Credits remaining: #{balance}"
| HTTP Status | Meaning | What to do |
|---|---|---|
| 200 OK | The request was processed. Check State — a result with State = "Unknown" and a RetryAfterSeconds value is an interim answer, not a final verdict. |
Use the result. If State is Unknown, retry the same request after RetryAfterSeconds. |
| 400 Bad Request | Missing email/token parameter, no credits remaining, or a transient processing failure. |
Check the response text. If you are out of credits, top up your balance before retrying. |
| 401 Unauthorized | The API key is invalid or unknown. | Verify the token value against the API key shown in your dashboard. |
| 403 Forbidden | The account attached to this API key is inactive. | Contact info@validemail.net to reactivate the account. |
| 429 Too Many Requests | You exceeded your per-second request limit. The response body includes the configured limit. | Slow down and retry with backoff, or contact us to raise your rate limit. |
Explore every response field and status code in the full API reference.