Class: MailBoxValidator::MailBox

Inherits:
Object
  • Object
show all
Includes:
Singleton
Defined in:
lib/mail_box_validator/mail_box.rb

Instance Method Summary collapse

Instance Method Details

#mail_exchanger_record_for(domain) ⇒ Object



14
15
16
17
18
# File 'lib/mail_box_validator/mail_box.rb', line 14

def mail_exchanger_record_for(domain)
  Resolv::DNS.open do |dns|
    dns.getresources(domain, Resolv::DNS::Resource::IN::MX).map { |r| r.exchange.to_s }
  end
end

#valid?(mail_address) ⇒ Boolean

Returns:

  • (Boolean)


8
9
10
11
12
# File 'lib/mail_box_validator/mail_box.rb', line 8

def valid?(mail_address)
  domain = mail_address.slice(/@(.*)/, 1)
  mx = mail_exchanger_record_for(domain)
  mx.present? && mx.any?(&return_valid?(mail_address))
end