Integrations · E-commerce
Validate emails in Magento 2
The email-validation.org module for Magento Open Source and Adobe Commerce checks the email address of every new customer account and every order placed on your storefront, and stops the ones you choose with one plain message. When you ask, it also checks your existing customers and orders as one bulk list. When our API cannot answer, the customer goes on: a check that fails never stops a sign-up or an order.
The module is not on the Adobe Commerce Marketplace or Packagist yet: you install it from the zip on this page.
Before you start
- An API key from the API keys page, with Validate addresses for new accounts and orders, Read balance and usage to show your balance on the bulk check page, and Bulk lists for the bulk check. Set a daily credit cap on the key: without one, only your balance limits what a busy store, or a script on Magento 2.4.9 (see the visitor limit), can spend.
- Magento Open Source or Adobe Commerce 2.4.7, 2.4.8 or 2.4.9, on the PHP version that release supports (2.4.7: PHP 8.2 or 8.3; 2.4.8: 8.3 or 8.4; 2.4.9: 8.5).
- A shell on the server to run
bin/magento, and Magento's cron running (bin/magento cron:install): the bulk check moves on a minute at a time.
Install
Download email-validation-module-email-check.zip. It holds the module's files and its MIT licence under
EmailValidation/EmailCheck/, built from the module's tested source. SHA-256:acdf7503b4c16950abdfa7923654dc583b758029bb05445cb983955c1711d727.From your Magento root, unzip it into
app/code, where Magento keeps a module that is not installed with Composer, then enable it:unzip email-validation-module-email-check.zip -d app/code bin/magento module:enable EmailValidation_EmailCheck bin/magento setup:upgrade bin/magento setup:di:compile # in production mode bin/magento indexer:reindex customer_grid # once: the customer grid's "Email check" column bin/magento cache:flushIn the admin, open Stores → Configuration → Customers → Email validation. Paste your key in API key and click Save Config. The key is stored encrypted with your install's own key and the field shows only asterisks from then on.
Pick the Data residency (US, or EU to have addresses validated in the EU and lists and results stored there), and, per website or store view if you like, the results that stop a new account and an order. The defaults stop
invalidanddisposableaddresses on a new account, and onlyinvalidones at the checkout.
Try it
Try it on a staging copy of your store if you have one. Turn the store's mail off first: Stores → Configuration → Advanced → System → Mail Sending Settings → Disable Email Communications: Yes, because an account that is not stopped is created and gets its welcome mail. On a live store this stops every mail the store sends, order confirmations and password resets included, until you switch it back.
Then, with Check new accounts on and invalid among the stopped results (both are the defaults), open your storefront's Create an Account page and register with no_mailbox@sandbox.email-validation.org. The message appears and no account is created. Addresses on sandbox.email-validation.org give each answer for free: disposable@… is stopped by default too, while catch_all@… is let through unless you add catch_all to the stopped results.
If the account is created, the check did not run: var/log/system.log has a line starting Email validation: with the reason (see If a check cannot finish). When you are done, delete the test customer and turn the mail back on: set Disable Email Communications back to No, at the scope where you set it. Never try it with an address that passes (such as accepted@…): Magento makes the account.
What is checked
| Where | When | Stops by default |
|---|---|---|
| New account | the storefront registration form, and GraphQL createCustomer and createCustomerV2 | invalid, disposable |
| Placed order | the storefront checkout (its REST calls), the REST API's cart place-order calls, and GraphQL placeOrder, guests included | invalid only |
Each has its own switch and its own list of stopped results, per website and store view. You can stop invalid, disposable, catch_all and unknown; a valid address is never stopped. See what each status means. Each result is saved on its customer or order: the customer grid's Email check column filters customers by it.
What customers see when an address is stopped, whatever the reason (you can set your own text under Message):
Please check your email address: we cannot deliver mail to it.
The registration form shows it and keeps the visitor on the form; the checkout shows it at the place-order button. Nothing is created.
No paid order is refused
An order is stopped only inside the checkout's own place-order step, before Magento takes any payment. An order that a payment method creates after the shopper paid on the provider's own page (PayPal Express, for one) is checked and its result saved, but it is never stopped.
A check waits at most 7 seconds. The same address checked again within the hour, such as a retried checkout, reuses its answer and costs no second credit; an unknown answer is asked again.
When the checkout stops an order, Magento's own checkout writes that message to var/log/system.log with a stack trace, which can show the start of a guest's address. That line is Magento's; the module's own lines never hold an address.
If a check cannot finish
A timeout, no connection, no credits, a refused key, the key's daily cap, no key, our API out of reach or an error in the store itself (its cache, for one): the account or the order goes through, and a warning starting Email validation: is written to var/log/system.log with the reason and our error code, and our request id when there is one, never the address or the key. No setting changes this: a failed check never stops anyone. Look up the error code on the errors page.
unauthorized: copy the whole key again from the API keys page, check it has the "Validate addresses" permission, and save it again.insufficient_creditsorkey_daily_cap: buy credits or raise the key's cap; addresses pass unchecked until then.- Too many checks from one visitor: a visitor causes about 20 paid checks an hour (requests at the same moment can pass a few more); over that, the address passes unchecked and a log line says the visitor limit was reached. The visitor is the IP address Magento sees (an IPv6 address counted by its /64), and which one that is depends on the release:
- Magento 2.4.7 and 2.4.8 (up to 2.4.7-p10 and 2.4.8-p5) use the address that connected to PHP. Reached directly, the limit holds. Behind a reverse proxy, Varnish, a load balancer or a CDN, every visitor counts as the proxy, and checks stop for everyone after the limit, unless your web server restores the visitor's address (for example with nginx's real-IP module or Apache's mod_remoteip).
- Magento 2.4.9 reads the
X-Forwarded-Forheader and uses its first entry. A visitor can set that entry, so there the limit holds only when your web server or proxy replaces the header with the address it sees, instead of adding to it or passing it on. A header with no valid IP address in it (any text) leaves Magento with no address at all, and a check without an address is not counted: a script then needs no new address per request. - Set a daily credit cap on the key. It holds whatever the release and the proxy. Without one, on 2.4.9, unless your web server or proxy replaces
X-Forwarded-For, a script can spend your whole balance.
What is not checked
Customers and orders made in the admin, by an import or by cron; customers made through the REST API; orders an integration creates without the cart's place-order call (POST /V1/orders, for one); multishipping checkout orders; orders that a payment method's own code creates without Magento's quote submission; newsletter sign-ups and the contact form, which create no account and no order. An integration that places orders through the cart endpoints (PUT /V1/carts/:cartId/order, with an integration's token too) is checked like the checkout (its server counts as one visitor: after about 20 checks an hour, the rest pass unchecked). Hyvä and PWA Studio storefronts are checked where they create accounts and place orders through Magento's GraphQL. The check runs when the customer presses the button, not while they type.
The bulk check below covers everything the storefront checks miss.
Check your existing customers and orders
Customers → Email check → Count addresses counts every customer account and every order, guest orders included, and shows the number of addresses, the most it can cost (one credit per distinct address) and your balance. Nothing is sent until you tick the box and confirm. The check then runs in the background through cron; the page shows where it stands, and Cancel returns unused credits.
One bulk list holds at most 1,000,000 rows (customer accounts and orders together) and 100,000,000 bytes. A larger store is checked in parts, one after another: the figure you confirm and the credits are for the whole store, every address is in one part only (so it is charged once), and each part's results are saved before the next part is sent. If a part stops (for example, for credits), Try again goes on with that part; the parts already done are not checked again. If a part's bulk list ends without results, Count the remaining parts asks for a new figure for that part and the parts after it only.
From the command line:
bin/magento email-validation:clean start # counts, shows the credits, asks y/N
bin/magento email-validation:clean run # works it now instead of waiting for cron
bin/magento email-validation:clean statusThe module never deletes or changes a customer or an order: filter the customer grid by Email check (or open the Email check page's list, by customer and order id) and decide what to do with each.
Ending access
On Stores → Configuration → Customers → Email validation, empty the API key field and click Save Config. The stored key is deleted and nothing more is sent.
Revoke the key on the API keys page.
To remove the module, run these from your Magento root, in this order:
bin/magento module:uninstall --non-composer EmailValidation_EmailCheck # removes the "Email check" attribute bin/magento module:disable EmailValidation_EmailCheck rm -rf app/code/EmailValidation/EmailCheck bin/magento setup:upgrade bin/magento cache:flushIts table email_validation_result (hashes and statuses, never an address) and its settings under
email_validation/stay in the database; drop them yourself if you want them gone. Keep the order: asetup:upgraderun aftermodule:disablebut beforerm -rfdrops that table.
Privacy
The key is sent only to our API, in the Authorization header, and is never in a log line, a message or a page. The module never logs an address. For each checked customer and order, its own table keeps the status, the reason, a SHA-256 of the address (never the address), where it was checked and when. Magento's cache keeps a status for an hour and each visitor's hourly count, both keyed by hashes. The bulk check's list and results files sit in var/email_validation/ only while it runs. The module sends no mail.