EmailCheck

Gem Version Build Status Dependency Status Code Climate Coverage Status

Description

This was built for Anonybuzz. This gem provides a robust mechanism to validate email addresses and restrict account creation to corporate email accounts.

This gem also ships with a data-set of free and disposable email domains which are used for validation checks.

Validation mechanisms

  • Uses the mail gem.
  • Checks the domain's MX record
  • Validate against a blacklist of domains
  • Validates against a list of free email providers
  • Validates against a list of disposable email providers
  • A whitelist can be used to override these checks

Installation

Add this line to your application's Gemfile:

gem "check_email"

Usage

Use with ActiveModel

To validate just the email address:

class User < ActiveRecord::Base
  validates :email, email: true
end

To validate that the domain has a MX record:

validates :email, email: { mx: true }

To validate that the email is not from a disposable or free email provider:

validates :email, email: { disposable:true, free:true }

To validate that the domain is not blacklisted:

validates :email, email: { blacklist:true}

Everything together:

validates :email, email: { mx: true, disposable:true, free:true, blacklist:true}

Modifying inbuilt lists

The lists are exposed as assignable arrays so you can customize them or load whatever data you please.

Add a config/intializers/email_check.rb

# Set disposable email domains
EmailCheck.disposable_email_domains = ['freemail.org']
# Append to the whitelist
EmailCheck.whitelisted_domains << 'gmail.com'
EmailCheck.free_email_domains << 'thenewgmail.com'
# Setting a domain in the blacklist also will blacklist all subdomains
EmailCheck.blacklisted_domains << 'lvh.me'

Requirements

This gem is tested with Rails 4.0. Ruby versions tested:

  • Ruby 2.0
  • Ruby 2.1
  • Ruby 2.2

Credits

This code is heavily based upon: lisinge/valid_email2 Data is from: lavab/disposable and willwhite/freemail

Contributing

  1. Fork it ( https://github.com/dapatil/email_check/fork )
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create a new Pull Request