Here is a mass Emailer that uses a TK front end. If you don’t want the
front end you can just remove the calls and such…no big. It uses 2
files the **.txt file holds the Emails and the **.html holds the actual
page.
############START SCRIPT###########
require ‘fileutils’
require ‘net/smtp’
require ‘tk’
begin
root = TkRoot.new(‘background’=>‘white’){title “My Frontend”}
$text = TkText.new(root, ‘width’=>30){ background ‘white’;
pack(“padx”=>1, “pady”=>1, “side”=>‘left’)}
$emailName = Array::new
$emailAddress = Array::new
$eT = File.read(‘test_par.html’)
IO.foreach(‘emails.txt’,’\n’) do |line|
$text.insert(‘end’, “#{line}”)
end
class SendEmail
def send_mail
$emailName = $text.value
#text.value.each do |name|
# p name.scan(/.*?[^\[^\]^\n]$/).flatten
#end
$emailName.each do |name|
begin
$address = name.scan(/.*?[^\n]$/).flatten #separate out the Email
address
Net::SMTP.start('mail.hrsmart.com', 25, 'localhost','EMAIL ACCOUNT
NAME’,‘PASSWORD’, :plain) do |smtp|
smtp.open_message_stream(‘FROM EMAIL ADDRESS’, $address) do |f|
f.puts ‘From: [email protected]’
f.puts “To: #{$address}”
f.puts "MIME-Version: 1.0
f.puts “Content-type: text/html”
f.puts ‘Subject: January Tattoo Specials’
f.puts
f.puts “#{$eT}”
end
end
#puts message
#p $address
rescue Exception => e
puts "Could not send to #{$address} - #{e.message}\n"
#puts e.backtrace.inspect
end
end
end
end
TkButton.new(root, ‘background’=>‘blue’, ‘foreground’=>‘white’){text
“Send Mail”; command{SendEmail.new.send_mail}; pack(‘side’=>‘left’,
‘padx’=>1, ‘pady’=>1)}
rescue
print “Exception occured\n”
end
Tk.mainloop
############END SCRIPT###########