Two checks of an address typed into a public sign-up form, both about its domain and neither about whether an account exists:
check/1asks DNS whether the domain can receive mail at all, so a sign-up forsomeone@no-such-domain.exampleis refused before a mail is sent that can only bounce;suggestion/1spots the common typos of the big providers (gmial.com,hotmail.con) and offers the corrected address. It is a hint: nothing is refused for it and DNS is not asked.
On by default; the switch is on Settings → Authorization → Abuse protection
(email_domain_check_enabled). config :phoenix_kit, :email_domain_check, false switches both off whatever the setting says: for a test environment,
where sign-ups use addresses like user@example.com (a domain that really
does publish "no mail here") and DNS may not be reachable.
Only a definite answer refuses
check/1 refuses when DNS says the domain does not exist, when it has
neither a mail host (MX) nor an address (A/AAAA: the fallback mail servers
use), or when it publishes a null MX (RFC 7505, "this domain takes no
mail"). A timeout, a resolver error or anything else unreadable passes: a
DNS hiccup must not close sign-up. Non-ASCII and address-literal domains are
not looked up.
Call it on a submit only, after the bot check and the rate limiter, so the
form cannot be used to make the server do lookups for free
(Auth.register_user/3 with check_email_domain: true and
MagicLinkRegistration.send_registration_link/3 do).
Summary
Functions
Whether the address's domain can receive mail. :ok while the check is off,
for a domain that can, and whenever DNS gave no definite answer.
Whether the checks run (the setting, default on, and the config override).
The setting key of the switch.
suggestion/1 without the switch: the pure rule.
The address with a likely typo in its domain corrected, or nil when there
is nothing to suggest (or the check is off).
Functions
@spec check(term()) :: :ok | {:error, :no_mail_host}
Whether the address's domain can receive mail. :ok while the check is off,
for a domain that can, and whenever DNS gave no definite answer.
@spec enabled?() :: boolean()
Whether the checks run (the setting, default on, and the config override).
@spec setting_key() :: String.t()
The setting key of the switch.
suggestion/1 without the switch: the pure rule.
The address with a likely typo in its domain corrected, or nil when there
is nothing to suggest (or the check is off).
iex> PhoenixKit.Users.EmailDomain.suggest("ann@gmial.com")
"ann@gmail.com"