Last active
February 5, 2025 10:34
-
-
Save jfqd/4fe5445efc4054a493f77684fd3a86d0 to your computer and use it in GitHub Desktop.
This file contains 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' | |
file = ARGV[0] | |
if file.nil? || file == "" | |
puts "email-mx-check /path/to/file-with-emails-line-per-line" | |
exit | |
else | |
puts "the following domains have a missing mx-entry:" | |
end | |
def valid_domain_mx_entry?(e,result=false) | |
fqdn = if e.include?("@") | |
e.split("@")[1] | |
else | |
e | |
end | |
if !fqdn.nil? && fqdn != "" | |
mx_records = Resolv::DNS.open(nameserver: ['9.9.9.9']) do |dns| | |
dns.getresources(fqdn, Resolv::DNS::Resource::IN::MX) | |
end | |
result = true if !mx_records.nil? && mx_records != [] | |
end | |
result | |
end | |
File.readlines(file, chomp: true).each do |line| | |
puts(line) if !line.nil? && line != "" && !valid_domain_mx_entry?(line.downcase) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This script checks if there is an mx entry for each email-address listed in the given file and outputs the email-addresses without an mx-entry. Optional you can give list of domains in the file.