0.05
No commit activity in last 3 years
No release in over 3 years
Email Veracity abstracts an email address into a series of objects which makes it easy to see if an address is invalid, and if so, why.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

= 0.9.8
= 2.10.3
 Project Readme

DEPRECATION NOTICE

Email Veracity was my very first open source project. Six years ago, it seemed like a cool idea, but it's now pretty common knowledge that trying to validate email addresses beyond a loose format check will likely yield false-positives. The whole idea of including a library for that seems silly.


Email Veracity 101

Let's explore the different functionality that Email Veracity provides and some simple ways you can integrate this functionality into your code without needing to rely on a flaky guy like me!

Validating an address for format

Trying to explicitly validate an email address for total RFC compliance is extravagantly complex, so why bother? Send a verification email to ensure that the user has provided a functioning address. If you still think that having a more robust check is necessary, the regex used in Email Veracity is from here and is a pretty good compromise between obscene complexity and useful robustness.

email = 'bizdude@example.biz'

if email =~ /\A[^@]+@[^@]+\Z/
  puts 'probably valid'
  send_verification_to(email)
else
  puts 'definately not valid'
end

Extracting the domain portion of an email address

There are libraries out there for formally parsing email addresses and you can use those to get the domain portion of the email address, but we can also just use a little regular expression.

email = 'megabiz@social-expert-megasite-seo.com'
match = /@([\w\.\-]+)\Z/i =~ email

if match
  puts 'domain is: ' + match[1]
else
  puts 'no domain found'
end

Looking up records on the domain

I highly discourage using this method to actually validate email addresses in-line with a request; it will absolutely yield false-positives.

require 'resolv'

A  = Resolv::DNS::Resource::IN::A  # Address records
MX = Resolv::DNS::Resource::IN::MX # Mail-exchange records
NS = Resolv::DNS::Resource::IN::NS # Name server records

def lookup(host, type)
  Resolv::DNS.new.getresources(host, type)
end

a_records  = lookup('gmail.com', A)
mx_records = lookup('gmail.com', MX)
ns_records = lookup('gmail.com', NS)

puts a_records.map { |r| r.address.to_s }
puts mx_records.map { |r| r.exchange.to_s }
puts ns_records.map { |r| r.name.to_s }

Check out the Ruby Standard Library Documentation for more ways to use Resolv::DNS in your project.