Skip to content

Instantly share code, notes, and snippets.

@aghyad
Created December 3, 2013 22:42
Show Gist options
  • Save aghyad/7778914 to your computer and use it in GitHub Desktop.
Save aghyad/7778914 to your computer and use it in GitHub Desktop.
Validating email dns in ruby
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