Integrations · AI tools
Check email addresses in your Botpress bot
Check the email address your Botpress bot asks for while the conversation is still going: a bot that collects leads or sign-ups can ask again right away when an address cannot receive mail, or is a throwaway inbox, instead of saving it. The check is the code of one Execute Code card, placed after the Capture Information card that asks for the address. It writes the verdict to Workflow variables, and an Expression card sends the conversation back to ask again. If the check cannot be made, the conversation carries on as if the card were not there.
There is nothing to install from the Botpress Hub: you paste one file into the card. It is check-email.js, shown in full below.
Set it up
- Create an API key on the API keys page with the permission Validate addresses and a daily credit cap.
- In Botpress Studio, select Bot Settings at the bottom left, scroll to Configuration Variables, select + and add
EMAIL_VALIDATION_API_KEYwith your key. Botpress keeps configuration variables encrypted, and the card reads the key from there, so it never sits in the code. - In your Workflow, ask for the address with a Capture Information card of type Email Address that saves it in a Workflow variable named
userEmail. - Open the Workflow's variables and create four of type String:
emailDecision,emailStatus,emailReasonandemailSuggestion. The card writes all four. - Add an Execute Code card right after the Capture Information card, in the same node or the next one, and replace its code with the whole of
check-email.js: copy it from the box below. - After it, add an Expression card. Turn off the AI for its Condition and enter
workflow.emailDecision === 'flagged'. Connect it to a node that tells the person the address cannot be used, offers the corrected address inemailSuggestionwhen it is not empty, and goes back to the Capture Information card. Everything else carries on to the rest of your flow. On that Capture Information card, keep the options that skip the question whenuserEmailis already filled, or take the answer from earlier messages, turned off: otherwise it does not ask again, the card checks the same address again, and each round costs a credit. - Try it in the Emulator. Give
no_mailbox@sandbox.email-validation.org: the bot asks again. Giveaccepted@sandbox.email-validation.org: it carries on. Test addresses return the result their name says, cost nothing and contact no mail server. If a later step of your flow sends email or adds the person to a mailing list, end the test before it: a test address receives no mail, and a bounce hurts the sender.
The card's code
Or open check-email.js as plain text in a new tab, select all of it and copy it from there.
Settings
The settings are at the top of the card's code. Your key is not one of them: it stays in the configuration variable.
| Setting | Value |
|---|---|
givenAddress | The Workflow variable the Capture Information card saved the address in: workflow.userEmail. Change the name if yours is different. |
apiHost | Our US host. Use the commented line under it, https://api-eu.email-validation.org, for EU data residency. Both use the same keys and credits; any other host is refused, so your key goes nowhere else. |
flagStatuses | The statuses that make the decision flagged. The default is invalid and disposable. Add catch_all or unknown to flag those too, or remove disposable to let throwaway inboxes through. |
timeoutMs | How long the card waits for our answer, in milliseconds, from 1 to 30000. The default is 10000. The upper bound keeps the card well inside the 60 seconds Botpress gives a bot to handle a message. Below about 7000, a check our API is still answering (it answers within 5 seconds) may be cut off and still cost a credit. |
Flagging more than the default turns away more real people: a catch_all domain accepts mail for every address, so the mailbox may well exist, and an unknown result means the mail server did not let us check. An unknown result caused by our own side (reason timeout or internal_error) is never flagged, whatever you choose.
A result marked disposable is flagged while disposable is on the list, whatever its status (the API keeps invalid or unknown as the status of some addresses on disposable domains), except an unknown that means our check ran out of time or failed.
What the card writes
| Variable | Value |
|---|---|
emailDecision | flagged, allowed, or unchecked when the check could not be made. |
emailStatus | One of our five statuses, or empty when unchecked. |
emailReason | Our reason, or why the address was not checked (below). |
emailSuggestion | A corrected address when the API suggests one (Did you mean …?), else empty. |
Only these four variables change. The card logs nothing, and a reply from our API can only ever put our own statuses, reasons and codes, or one email address, into them.
When the check cannot be made
Then emailDecision is unchecked and your flow carries on, as long as your Expression card tests only for flagged. The card never throws, so the conversation never stops on it. emailReason says why:
emailReason | Why |
|---|---|
not_an_address | The variable does not hold one email address (a link, a mailto:, several addresses or nothing at all). Nothing was sent. |
missing_key | EMAIL_VALIDATION_API_KEY is missing or not a key. Nothing was sent. |
bad_setting | A setting at the top of the code is not one the card accepts. Nothing was sent. |
no_axios | The card found no Axios to send with (Botpress provides it to every Execute Code card). Nothing was sent. |
timeout | No answer within timeoutMs, or our check itself ran out of time. |
connection_error | Our API could not be reached. |
unauthorized, insufficient_credits, rate_limited, … | Our API's error code: a wrong key, no credits left, too many checks at once. |
internal_error, unexpected_response, http_ and a number | Something went wrong on our side, or an answer we did not expect. |
card_error | Something unexpected went wrong inside the card itself. |
The card sends one request per run and never resends it, so the person never waits longer than timeoutMs. It never follows a redirect, so your key goes only to our host.
What it costs
Each check costs at most 1 credit, as with any validation request; unknown results, errors and test addresses are free. Each time the card runs, it checks again: a person who gives the same address twice is checked twice, and a repeat check also costs 1 credit. Credits come in one-time packs, as little as $0.15 per 1,000 with the 50,000,000-credit pack (smaller packs cost more per credit), and new accounts get 500 free credits (100 when you sign up with a free email provider such as Gmail, Outlook or Yahoo, another personal mailbox such as a paid one like Fastmail or one from your internet provider, or an address from a relay or alias service). The key's daily credit cap bounds what a busy bot can spend; once it is reached, addresses are unchecked until the cap resets.
What we receive
The card sends only the email address, to our US or EU host. Not the conversation, the person's name or anything else from Botpress.