# `PhoenixKit.Users.EmailDomain`
[🔗](https://github.com/BeamLabEU/phoenix_kit/blob/v3.6.0/lib/phoenix_kit/users/email_domain.ex#L1)

Two checks of an address typed into a public sign-up form, both about its
domain and neither about whether an account exists:

  * `check/1` asks DNS whether the domain can receive mail at all, so a
    sign-up for `someone@no-such-domain.example` is refused before a mail is
    sent that can only bounce;
  * `suggestion/1` spots 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).

# `check`

```elixir
@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.

# `enabled?`

```elixir
@spec enabled?() :: boolean()
```

Whether the checks run (the setting, default on, and the config override).

# `setting_key`

```elixir
@spec setting_key() :: String.t()
```

The setting key of the switch.

# `suggest`

```elixir
@spec suggest(term()) :: String.t() | nil
```

`suggestion/1` without the switch: the pure rule.

# `suggestion`

```elixir
@spec suggestion(term()) :: String.t() | nil
```

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"

---

*Consult [api-reference.md](api-reference.md) for complete listing*
