Created
December 3, 2013 22:42
-
-
Save aghyad/7778914 to your computer and use it in GitHub Desktop.
Validating email dns in ruby
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'resolv' | |
def validate_email_domain(email) | |
domain = email.match(/\@(.+)/)[1] | |
Resolv::DNS.open do |dns| | |
@mx = dns.getresources(domain, Resolv::DNS::Resource::IN::MX) + dns.getresources(domain, Resolv::DNS::Resource::IN::A) | |
end | |
@mx.size > 0 ? true : errors.add(:email, "Invalid email id") | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment