Created
October 5, 2015 13:25
-
-
Save sled/4d880b7c5d5a311a07f0 to your computer and use it in GitHub Desktop.
Checks whether a mail is probably a google apps email
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
require 'resolv' | |
require 'public_suffix' | |
email = ARGV[0] | |
domain = email.split("@").last | |
servers = %w(googlemail.com, google.com) | |
# get the server with lowest preference number -> highest priority! | |
mail_server = Resolv::DNS.open.getresources(domain, Resolv::DNS::Resource::IN::MX).min_by{|s| s.preference} | |
# grab TLD and compare with our list of servers | |
is_valid = mail_server.nil? ? false: servers.include?( PublicSuffix.parse(mail_server.exchange.to_s).domain) | |
puts "Is google apps:", is_valid |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment