Skip to content

Instantly share code, notes, and snippets.

@asim
Created August 8, 2010 15:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save asim/514162 to your computer and use it in GitHub Desktop.
Save asim/514162 to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
require 'net/smtp'
FILE = File.readlines("foo1")
class Email
def initialize
@smtp = Net::SMTP.new('127.0.0.1', 2025)
end
def post(from, to)
msgstr = <<EOF
From: <#{from}>
To: <#{to}>
Subject: Fooo
Date: #{Time.now}
Message-Id: <#{Time.now.to_i}.#{from}>
MIME-Version: 1.0
Content-type: text/plain
#{FILE}
EOF
@smtp.start do |smtp|
smtp.send_message msgstr, from, to
end
end
end
def nonthreaded
counter = 0
email = Email.new
while counter < 100
email.post("foo@foo.com", "bar@bar.com")
puts counter += 1
end
end
def threads
require 'thread'
q = Queue.new
1000.times do
Thread.new do
1.times do |i|
q << Email.new
end
end
end
puts "Queued"
f = Thread.new do
1000.times do |k|
email = q.shift
email.post("foo@foo.com", "bar@bar.com")
puts k
end
end
f.join
end
send(ARGV[0])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment