EmailDoHChecker
EmailDoHChecker is an Elixir library designed to check the validity of email domains using DNS-over-HTTPS (DoH). It allows you to verify whether a domain resolves correctly or is blocked by a DNS provider. Defaults to using the NextDNS DoH server, and can be used with a profile. Powerful in combination with your own configuration in the profile, such as blocking malicious domains.
Features
- Validate domains and email addresses.
- Use DNS-over-HTTPS to perform domain resolution.
- Configurable DoH server URL.
- Easy configuration through DNS server profiles (e.g. NextDNS).
Installation
Add :email_doh_checker to your list of dependencies in mix.exs:
def deps do
[
{:email_doh_checker, "~> 0.1.1"}
]
endThen, run mix deps.get to fetch and install the dependency.
Configuration
You can configure the default DoH server URL in your application's configuration:
# config/config.exs
config :email_doh_checker,
doh_server: "https://dns.nextdns.io/"Usage
Here's an example usage of the EmailDoHChecker library:
iex> EmailDoHChecker.valid?("example.com")
true
iex> EmailDoHChecker.valid?("user@example.com")
true
iex> EmailDoHChecker.valid?("blocked@blocked.example")
falseWith Ecto
You can also use the EmailDoHChecker library with Ecto to validate email domains in your Ecto schemas:
def changeset(model, params) do
model
|> cast(attrs, [:email])
|> update_change(:email, &String.trim/1)
|> validate_email()
end
@email_regex ~r/\A([\w+\-].?)+@[a-z\d\-]+(\.[a-z]+)*\.[a-z]+\z/i
defp validate_email(%{changes: %{email: email}} = changeset) do
case Regex.match?(@email_regex, email) do
true ->
case EmailDoHChecker.valid?(email) do
true -> add_error(changeset, :email, "forbidden_provider")
false -> changeset
end
false -> add_error(changeset, :email, "invalid_format")
end
end
defp validate_email(changeset), do: changesetAcknowledgements
This library is inspired by Burnex and EmailChecker.
License
This project is licensed under the MIT License - see the LICENSE file for details.