Skip to content

Instantly share code, notes, and snippets.

@coderhs
Created April 4, 2013 13:52
Show Gist options
  • Save coderhs/5310513 to your computer and use it in GitHub Desktop.
Save coderhs/5310513 to your computer and use it in GitHub Desktop.
require 'resolv'
class MxRecordValidator < ActiveModel::EachValidator
def validate_each(record, attribute, value)
mail_servers = Resolv::DNS.open.getresources(value.split('@')[1], Resolv::DNS::Resource::IN::MX)
if mail_servers.empty? then
record.errors[attribute] << "Does not have a MX record assosiated with mail id"
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment