Last active
January 4, 2016 08:09
-
-
Save ylluminate/8593384 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 'net/smtp' | |
module MailMachine | |
class NetSmtp < Net::SMTP | |
class << self | |
EXCEPTIONS = [Net::SMTPAuthenticationError, | |
Net::SMTPServerBusy, | |
Net::SMTPSyntaxError, | |
Net::SMTPFatalError, | |
Net::SMTPUnknownError, | |
Net::OpenTimeout] | |
def start_server(server, port, helo, from, to) | |
## Options for sent mail ## | |
# `server` - typical 'localhost' #string | |
# `port` - typical '9999' #integer | |
# `helo` - domain name server.Should be good! #string | |
# `from` - from email or name #string | |
# `to` - email to #string | |
############################################ | |
## Debug to mailcatcher | |
server ||= '127.0.0.1' | |
port ||= 1025 | |
helo ||= 'localhost' | |
####################### | |
begin | |
smtp = new(server, port).start(helo) | |
#Very bad open hole | |
smtp.set_debug_output $stderr | |
smtp.send_message("this can be email template", from, [to]) | |
smtp.finish | |
rescue *EXCEPTIONS => e | |
response = Net::SMTP::Response.parse(e.to_s) | |
rescue Exception => e | |
response = Net::SMTP::Response.new("666", e.to_s) | |
end | |
response ||= Net::SMTP::Response.new("250", "Email delivery") | |
end | |
end | |
end | |
end |
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' | |
module MailMachine | |
class Validator | |
def initialize(name) | |
@name = name.split('@').last | |
end | |
def servers_list | |
Resolv::DNS.open.getresources(@name, Resolv::DNS::Resource::IN::MX).map do |resolv| | |
resolv.exchange.to_s | |
end | |
end | |
def server | |
servers_list.find do |name| | |
Resolv.getaddress(name) =~ Resolv::AddressRegex | |
end | |
rescue Resolv::ResolvError => e | |
#holly molyy | |
return false if e.is_a? Exception | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment