Skip to content

Instantly share code, notes, and snippets.

@jfqd
Last active February 5, 2025 10:34
Show Gist options
  • Save jfqd/4fe5445efc4054a493f77684fd3a86d0 to your computer and use it in GitHub Desktop.
Save jfqd/4fe5445efc4054a493f77684fd3a86d0 to your computer and use it in GitHub Desktop.
#!/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
@jfqd
Copy link
Author

jfqd commented Feb 5, 2025

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment