Created
March 15, 2009 16:05
-
-
Save eltiare/79460 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
require 'socket' | |
require 'base64' | |
class SSMTP < TCPSocket | |
def self.start(*args) | |
s = new(*args[0..1]) | |
s.start(*args[2..5]) | |
yield s | |
s.close | |
end | |
attr_accessor :verp | |
def initialize(*) | |
@remote_opts = {} | |
@remote_opts[:attrs] = [] | |
super | |
end | |
def start(ehlo = 'localhost.localdomain', user=nil, pass=nil, method = :login) | |
puts "EHLO #{ehlo}" | |
r = recv(500) | |
lines = r.gsub(/^250\-/).split(/\r\n/) | |
@remote_opts[:host_name] = lines.shift | |
lines.each do |line| | |
case line | |
when /^SIZE/ then @remote_opts[:max_size] = line.sub(/^SIZE /, '').to_i | |
when /^AUTH/ then @remote_opts[:login_methods] = line.sub(/^AUTH /, '').split(' ').map { |str| str.downcase.to_sym } | |
else @remote_opts[:attrs].push line | |
end | |
end | |
raise 'Not a remote accepted login method' unless @remote_opts[:login_methods].include?(method) | |
case method.to_sym | |
when :login | |
puts 'AUTH LOGIN' | |
#r << recv(500) | |
write Base64.encode64(user) | |
#r << recv(500) | |
write Base64.encode64(pass) | |
#r << recv(500) | |
else | |
raise "Unimplemented method: #{method}" | |
end | |
r | |
end | |
def send_message(msg, from, to) | |
if @verp | |
from = "<#{from}>" unless from.match('<') | |
from = "#{from} XVERP" | |
end | |
puts "MAIL FROM:#{from}" | |
puts "RCPT TO:#{to}" | |
puts "DATA", msg, '.' | |
recv(500) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment