Using NeverBounce Ruby API to Check Email Deliverability

It is important to maintain a good email reputation. You can see your email reputation in the dashboard.

Amazon SES Email Reputation Dashboard

I am using the gem neverbounce-api verion 1.0.4. Here is the code to validate with retries.

class EmailAddress
  MAX_RETRIES = 3

  def self.deliverable?(email)
    times_retried = 0
    begin
      client = NeverBounce::API::Client.new(api_key: Credential.never_bounce_secret_api_key)
      response = client.single_check(email: email)

       result = if response.ok?
         response.result == "valid"
       else
         false
       end
       result
    rescue Net::ReadTimeout => error
      if times_retried < MAX_RETRIES
        times_retried += 1
        retry
      else
        false
      end
    end
  end  
end

One of the exception that can occur is due to not having enough credits to make the API calls. I am not handling this exception in the code because you can configure NeverBounce to email you when the balance is low.

NeverBounce API Dashboard


Related Articles


Create your own user feedback survey