module BarkestCore::EmailTester

Adds helper methods to the model to allow verifying email addresses.

Constants

VALID_EMAIL_REGEX

A regex that can be used to verify most email addresses.

When used, the match will include a USER and DOMAIN element to represent the broken down email address.

Public Class Methods

valid_email?(email, check_dns = false) click to toggle source

Validates the supplied email address against the VALID_EMAIL_REGEX.

The check_dns option ensures that an MX record can be found for the email address.

# File lib/barkest_core/concerns/email_tester.rb, line 20
def self.valid_email?(email, check_dns = false)
  match = VALID_EMAIL_REGEX.match(email)
  return false unless match
  if check_dns
    return false if Resolv::DNS.open{ |dns| dns.getresources match['DOMAIN'], Resolv::DNS::Resource::IN::MX }.blank?
  end
  true
end