https://github.com/davidvanleeuwen/email_doh_checker
🤦♂️ Elixir checker of (email) domains using DNS-over-HTTPS (DoH)
https://github.com/davidvanleeuwen/email_doh_checker
Last synced: 6 months ago
JSON representation
🤦♂️ Elixir checker of (email) domains using DNS-over-HTTPS (DoH)
- Host: GitHub
- URL: https://github.com/davidvanleeuwen/email_doh_checker
- Owner: davidvanleeuwen
- License: mit
- Created: 2024-09-16T13:04:56.000Z (about 1 year ago)
- Default Branch: main
- Last Pushed: 2025-04-17T17:36:53.000Z (6 months ago)
- Last Synced: 2025-04-21T18:00:03.989Z (6 months ago)
- Language: Elixir
- Homepage:
- Size: 7.81 KB
- Stars: 2
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# EmailDoHChecker
[](https://github.com/davidvanleeuwen/email_doh_checker/actions)
[](https://coveralls.io/github/davidvanleeuwen/email_doh_checker?branch=master)
[](https://hex.pm/packages/email_doh_checker)
[](https://hexdocs.pm/email_doh_checker/)
[](https://hex.pm/packages/email_doh_checker)
[](https://hex.pm/packages/email_doh_checker)
[](https://github.com/davidvanleeuwen/email_doh_checker/commits/master)
`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`:
```elixir
def deps do
[
{:email_doh_checker, "~> 0.1.1"}
]
end
```
Then, run mix deps.get to fetch and install the dependency.
## Configuration
You can configure the default DoH server URL in your application's configuration:
```elixir
# config/config.exs
config :email_doh_checker,
doh_server: "https://dns.nextdns.io/"
```
## Usage
Here's an example usage of the EmailDoHChecker library:
```elixir
iex> EmailDoHChecker.valid?("example.com")
true
iex> EmailDoHChecker.valid?("user@example.com")
true
iex> EmailDoHChecker.valid?("blocked@blocked.example")
false
```
## With Ecto
You can also use the EmailDoHChecker library with Ecto to validate email domains in your Ecto schemas:
```elixir
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: changeset
```
## Acknowledgements
This library is inspired by [Burnex](https://github.com/Betree/burnex) and [EmailChecker](https://github.com/maennchen/email_checker).
## License
This project is licensed under the MIT License - see the LICENSE file for details.