ruby Ping一个电子邮件地址以查看它是否存在。此脚本解析MX记录以查找负责向广告发送邮件的SMTP服务器

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了ruby Ping一个电子邮件地址以查看它是否存在。此脚本解析MX记录以查找负责向广告发送邮件的SMTP服务器相关的知识,希望对你有一定的参考价值。

#!/usr/bin/env ruby
#
# = Email Ping
#
# Check to see if an email address exists by looking up MX records and connecting
# to the address's home SMTP server. It then starts to send a message to the address
# but quits before the message is actually sent.

require 'resolv'
require 'net/smtp'

address = ARGV[0].chomp
domain = address.split('@').last
dns = Resolv::DNS.new

puts "Resolving MX records for #{domain}..."
mx_records = dns.getresources domain, Resolv::DNS::Resource::IN::MX
mx_server  = mx_records.first.exchange.to_s
puts "Connecting to #{mx_server}..."

Net::SMTP.start mx_server, 25 do |smtp|
  smtp.helo "loldomain.com"
  smtp.mailfrom "test@loldomain.com"

  puts "Pinging #{address}..."

  puts "-" * 50

  begin
    smtp.rcptto address
    puts "Address probably exists."
  rescue Net::SMTPFatalError => err
    puts "Address probably doesn't exist."
  end
end

# vim: set ft=ruby ts=2 sw=2 :

以上是关于ruby Ping一个电子邮件地址以查看它是否存在。此脚本解析MX记录以查找负责向广告发送邮件的SMTP服务器的主要内容,如果未能解决你的问题,请参考以下文章

Ping随机IP以查看是否存在&ŧ039;的连接

用PING的命令怎么查看IP?

ping 不通的原因以及需要怎么做

ping命令有啥作用

ruby 电子邮件ping.rb

ping selenium hub以查看节点是否可用的方法?