Integrations · E-commerce

Validate emails at Solidus checkout and sign-up

Refuse an email address that cannot receive mail at your Solidus store's checkout and sign-up. A Ruby gem (a Rails engine) adds one validation to Spree::Order and to your customer account class (Spree.user_class, for example Spree::User of solidus_auth_devise), so the address is checked with our API whenever it is set or changed: the guest's address at checkout, a sign-up, an email change, an order made in the admin or through the API. By default only a definite invalid is refused: the person sees one sentence on the email field, as Solidus shows its own errors, and can correct the address.

It never refuses an address because our side could not answer. No key, a timeout, a network error, a rate limit or any error answer lets the address through, with one warning line in your logger. Only a definite answer refuses.

It cannot check an address Solidus writes without validations. Solidus copies a signed-in customer's account email onto their order without running validations, so that address is checked on the account, when it signs up or changes its email (below). Accounts made before you installed the gem were not checked.

Status: set up from this page. The gem is not on RubyGems and is not listed among Solidus's extensions: you download it here and add it to your Gemfile from a folder of your app. Its tests run against stand-ins for Solidus's classes; it has not yet been tried in a real Solidus store, so try it on a development copy of your store first.

Download it: email-validation-solidus-1.0.0.zip holds the gem's folder email-validation-solidus/: its gemspec, its code in lib/, a short README, the CHANGELOG and the MIT licence.

What you need

  • An API key of ours from the API keys page with Validate addresses (on by default), with a daily credit cap to limit what a busy store can spend. Keep it on your server.
  • A Solidus 4 store on Rails 7.2 to 8.1, with Ruby 3.2 or newer.
  • Bundler installs the official Ruby client library (email-validation-sdk 1.1 or a later 1.x) from RubyGems. The gem adds no Solidus gem of its own: it works with the Solidus your store already has.

Our key goes only to our two API hosts, and the client library never follows a redirect. Neither the address nor the key is ever logged.

Set it up

  1. Unzip the download into your app's vendor/ folder, so that you have vendor/email-validation-solidus/ with the gemspec in it. Bundler installs a gem from a folder that holds its .gemspec, and reads a relative path from the folder of your Gemfile (Bundler's Gemfile guide).

  2. Add it to your Gemfile, after solidus (and solidus_auth_devise if you use it), as Solidus's guide to extensions asks, and run bundle install:

    gem "email-validation-solidus", path: "vendor/email-validation-solidus"

    There is no generator to run and no migration: the gem stores nothing.

  3. Set your key in the server's environment as EV_API_KEY, or read it from your credentials in the initializer below. Never put it in code.

  4. Restart the app. When it loads, the engine adds the check to Spree::Order and Spree.user_class (and again after each code reload in development).

Every setting is optional. To change one, add config/initializers/email_validation.rb:

EmailValidation::Solidus.configure do |config|
  config.api_key = Rails.application.credentials.ev_api_key # default: ENV["EV_API_KEY"]
  config.logger = Rails.logger                              # the one warning line when a check cannot finish
  config.stop_on = %w[invalid disposable]                   # also refuse disposable addresses
  config.region = "eu"                                      # addresses validated in the EU, their results stored there
end

How it works

  1. Only a new or changed email. The check runs when a record is new or its email changes, never on the many other saves an order goes through at checkout. A record checked once for a value is not sent again for it in a row (valid? then save sends one request). A checkout step that fails for another reason leaves the email unsaved, so the next try checks it again.

  2. Nothing sent when Solidus already answers. A blank or malformed email that Solidus refuses itself, a cart with no email yet, an order whose email is its own customer account's (while accounts are checked) and a soft-deleted record (discarded?, or deleted_at set) are not sent. solidus_auth_devise scrambles a deleted account's email and saves it; that save goes through.

  3. One request, one decision. The address goes to our API once, never retried. An answer whose status is in stop_on (only invalid by default) adds an error on email with a sentence for the person, which the checkout and the admin show as they show Solidus's own:

    This address cannot receive email. Please check it for typos.

    Our own invalid sentence gets the API's "Did you mean …?" suggestion when there is one. The error's type is email_invalid (email_ and the verdict) in order.errors.details[:email]. Lists made with errors.full_messages put the field's name in front ("Email This address …"); pass your own messages to word it for that.

  4. Fails open. When the check cannot finish, the address goes through and one warning line goes to your logger with why, our error code, the HTTP status and the request id. With fail_open set to false, the field gets "We could not check this address right now. Please try again in a moment." instead. An unknown answer that means our side ran out of time (reason timeout or internal_error) never refuses, even with unknown in stop_on.

  5. A pause after a rate limit. After a 429 or 503 answer (other than key_daily_cap), no check is sent until its Retry-After (30 seconds without one, 300 at most), for the whole process; addresses pass meanwhile.

Signed-in customers. Solidus copies the account's email onto a signed-in customer's order without validations, so with check_users on (the default) that address is checked on the account instead. With check_users set to false, a signed-in customer's order email is in general not checked either; only an email typed on the checkout is.

EmailValidation::Solidus.check(email) checks an address you already have and returns an outcome with stop?, status, reason, did_you_mean, request_id, verdict and message (never the address). EmailValidation::Solidus.install!(order_class:, user_class:) adds the check to other classes with an email attribute.

Try it free first

First on your machine, with your key in EV_API_KEY, from your app's folder:

bin/rails runner 'o = EmailValidation::Solidus.check("no_mailbox@sandbox.email-validation.org"); puts [o.stop?, o.status, o.reason].join(" ")'
# prints: true invalid no_mailbox

false with no status means the check did not finish (no key in EV_API_KEY, for example); set config.logger to see why. Sandbox checks cost no credit. That domain receives no mail, so send it nothing: never type a sandbox address into your store's checkout or sign-up, where an address that gets through can be saved and mailed.

Then on a development copy of your store: go through a guest checkout with your own email address. It passes, and that check uses one credit unless the answer is unknown.

Options

SettingDefaultWhat it does
api_keyEV_API_KEYOur API key (Validate addresses), on the server only. Missing: nothing is checked.
regionEV_REGION, else useu checks the address in the EU and stores its result there (same key and credits).
stop_on%w[invalid]Statuses that refuse: invalid, disposable, catch_all, unknown. [] refuses nothing; valid never refuses.
fail_opentruefalse: a check that cannot finish refuses with the "unavailable" sentence.
check_orderstruefalse: orders are not checked.
check_userstruefalse: customer accounts are not checked.
timeout5Seconds our API may spend on the check (5 to 15); keep client_timeout a few seconds above it.
client_timeout8.0Seconds the request waits for the answer.
messagesoursYour sentences by verdict: invalid, disposable, catch_all, unknown, unavailable.
loggernoneAnything with warn(String), such as Rails.logger, for the one warning line.
transportthe client library'sA transport of the client library (a proxy).

Credits and limits

Each check uses one credit; unknown results and sandbox addresses are free. The gem keeps no answers between requests: an email set again on another record (the same customer's next guest order, say) is checked again.

The request runs while the record is being saved, so a slow answer keeps that save waiting for up to client_timeout seconds. Imports, seeds and scripts that save orders or accounts with an email through validations are checked too, one request per address; set check_users or check_orders to false in that process to skip them (the setting is for the whole process).

It fails open: no key, a timeout, a network error, a rate limit or any error answer lets the address through.

What each status means.

More on Solidus

Updated · Maintained by: Email Validation LLC

Need help? Contact support, or ask the help chat. Something wrong or missing on this page? Tell us