Giter Site home page Giter Site logo

email_checker's Introduction

EmailChecker

GitHub license Build Status Hex.pm Version Inline docs Coverage Status

Simple library checking the validity of an email. Checks are performed in the following order:

  • REGEX: validate the emails has a good looking format
  • MX: validate the domain sever contains MX records
  • SMTP: validate the SMTP behind the MX records knows this email address (no email sent)
    • ⚠️ That's rare but, some SMTP define a catchall email address. Meaning all emails using this domain seems valid even if they are not.
    • ⚠️ Most email providers nowadays don't support this method. You should only use it if you know what you're doing.

Installation

# mix.exs
def application do
  [mod: {YourModule, []},
   applications: [
     # other applications...
     :email_checker,
     # other applications...
     ]
  ]
end

def deps do
  [
    # other dependencies...
    {:email_checker, "~> 0.1.2"}
    # other dependencies...
  ]
end

Configuration

# config/config.exs -- default
config :email_checker,
  default_dns: :system,
  also_dns: [],
  validations: [EmailChecker.Check.Format, EmailChecker.Check.MX],
  smtp_retries: 2,
  timeout_milliseconds: :infinity

In the test environment, we need to manually load DNS records to validate if an MX exists or not. When we load the library Erlang doesn't have its DNS record list yet. So to avoid any problem, we define a default DNS. By default the value for the test environment is : {8, 8, 8, 8}, which is Google's primary public DNS server. If you find that you have odd failures in name resolution, you may have to specify a default DNS server.

In the case you need to load more DNS servers manually after the default one, you can set a list of more DNS server IPs in the also_dns setting.

Please note that the IP address is represented as a tuple separated by commas.

The default validations setting should be suitable for most cases. If you use fake but valid-looking email addresses in your own tests, you may need to set the validations to just [Format], and MX and SMTP testing will then not be used in that configuration.

The SMTP validation strategy will attempt 2 retries, by default.

The MX and SMTP validation strategies, each in their own way, use the same default timeout for net connections as the underlying Erlang library calls. It is important to note that this value is :infinity, and the call will take as long as the call takes. You likely want to set to a sensible timeout in milliseconds. Please note that:

  • For the MX validation, this is the timeout of the call to the DNS server for MX records.
  • For the SMTP validation, the timeout is divided by the number of retries.
# config/config.exs -- example personalized configuration
config :email_checker,
  default_dns: {8, 8, 8, 8},
  smtp_retries: 1,
  timeout_milliseconds: 6000

Usage

EmailChecker.valid?("[email protected]")
#=> true
EmailChecker.valid?("[email protected]")
#=> false

CHANGELOG

CHANGELOG

LICENSE

MIT

email_checker's People

Contributors

maennchen avatar kdisneur avatar hashnuke avatar xtian avatar maxinspace avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.