From: Diego Bernardes on
Hello!

I need to get mails from a mail server using pop3, save to disk to later
resend.

The get part:

pop = Net::POP3.new 'mail server'
pop.start 'address', 'password'

if pop.mails.empty?
puts "No mail"
else
puts "Have mails"

pop.mails.each_with_index do |m,i|
File.open("inbox/#{i}", "w+") do |f|
f.write m.pop
end
end
end


With this code i can download and save the mails into files.

Now i need get this files and resend as mails, this is the part isnt
working...

smtp = Net::SMTP.new 'mail address', port
smtp.start 'mail domain', 'username', 'password', :login

puts smtp.sendmail File.read(file from get path), 'from', 'to'


Well, the send part is broken, can anyone help me?
--
Posted via http://www.ruby-forum.com/.

From: seanh1313 on
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: bigdaddydigalow(a)hotmail.com'
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###########



---- Diego Bernardes <di3go.bernardes(a)gmail.com> wrote:
> Hello!
>
> I need to get mails from a mail server using pop3, save to disk to later
> resend.
>
> The get part:
>
> pop = Net::POP3.new 'mail server'
> pop.start 'address', 'password'
>
> if pop.mails.empty?
> puts "No mail"
> else
> puts "Have mails"
>
> pop.mails.each_with_index do |m,i|
> File.open("inbox/#{i}", "w+") do |f|
> f.write m.pop
> end
> end
> end
>
>
> With this code i can download and save the mails into files.
>
> Now i need get this files and resend as mails, this is the part isnt
> working...
>
> smtp = Net::SMTP.new 'mail address', port
> smtp.start 'mail domain', 'username', 'password', :login
>
> puts smtp.sendmail File.read(file from get path), 'from', 'to'
>
>
> Well, the send part is broken, can anyone help me?
> --
> Posted via http://www.ruby-forum.com/.
>