Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

email_check

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

email_check

  • 1.0.2
  • Rubygems
  • Socket score

Version published
Maintainers
1
Created
Source

EmailCheck

Gem Version Build Status Dependency Status Code Climate Coverage Status

Description

This was originally built for Anonybuzz and is now used at StarTalent. 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.

You can also block certain usernames from creating accounts. Examples: admin, root

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 "email_check"

Usage

Use with ActiveModel

To validate just the format of the email address

class User < ActiveRecord::Base
  validates_email :email
end

To validate that the domain has a MX record:

validates_email :email, check_mx: true

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

validates_email :email, not_disposable:true, not_free:true

To validate that the domain is not blacklisted:

validates_email :email, not_blacklisted:true

To validate that the username is not blocked

validates_email :email, block_special_usernames:true

Everything together:

validates_email :email,
    check_mx: true, 
    not_disposable:true, 
    not_free:true, 
    not_blacklisted:true,
    block_special_usernames:true,
    message: "Please register with your corporate email"

To turn everything on by default, you can use the validates_email_strictness helper.

# Example above
validates_email_strictness :email

# Everything but allow free emails. This is what most people would want to use
validates_email_strictness :email, not_free:false

Modifying the 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 will also blacklist all subdomains
EmailCheck.blacklisted_domains << 'lvh.me'
# Block the 'anonymous' username for all domains
EmailCheck.blocked_usernames << 'anonymous'

Requirements

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

  • Ruby 2.3
  • Ruby 2.5

Rails versions tested: Rails 4.0 Rails 5.0 Rails 6.0

Credits

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

FAQs

Package last updated on 06 Apr 2022

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc