Rich Email Validator
A set of helpers to validate emails:
It works as follows:
- Checks the availability of the mx records of the email's domain. This is done via a DNS lookup.
- Checks the format of the email via a regular expression that can be configured. This is done for performance only.
- Use a configurable number of threads to check thousands of emails in minutes.
Installation
Add this line to your application's Gemfile:
gem 'rich_email_validator'
And then execute:
$ bundle
Or install it yourself as:
$ gem install rich_email_validator
Usage
Validate an email
require 'rich_email_validator'
RichEmailValidator.valid_email?('khellls@gmail.com')
RichEmailValidator.valid_email?('khellls@g.com')
Set a predfined Regexp
It's only used for performace reasons to filter the format of an email before doing a DNS lookup check.
The current value is:
/\A[\w!
You can change it:
RichEmailValidator.email_regexp = /\A([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})\Z/i
Filter a list of emails
list = ['khellls@g.com', 'khellls@gmail.com']
RichEmailValidator.filter_list(list)
RichEmailValidator.filter_list(list, threads_count: 15)
Filter a list of emails from file
file_path = '/path/to/emails_list'
File.readlines(file_path).size
RichEmailValidator.filter_file(file_path).size
RichEmailValidator.filter_file(file_path, threads_count: 15)
Filter a list of emails from file and output to file
file_path = '/path/to/emails_list'
output_path = '/path/to/output'
File.readlines(file_path).size
RichEmailValidator.export_valid_list(file_path, output_path)
File.readlines('output.txt').size
RichEmailValidator.export_valid_list(file_path, output_path, threads_count: 15)
Contributing
- Fork it ( https://github.com/[my-github-username]/rich_email_validator/fork )
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create a new Pull Request