Hi guys,
I have a hard time with action mailer and TMail, I always get the
following error…
My code:
<<
pop = Net::POP3.new(‘pop.mydomain.com’)
pop.start(‘xxx’, ‘xxxxx’) # (1)
if pop.mails.empty?
puts ‘No mail.’
else
i = 0
pop.each_mail do |m| # or “pop.mails.each …” # (2)
File.open(“inbox/#{i}”, ‘w+’) do |f|
f.write m.pop
Mailman.receive(m.pop)
end
#m.delete
i += 1
end
puts “#{pop.mails.size} mails popped.”
end
pop.finish
#Mailmain
<<
class Mailman < ActionMailer::Base
def receive(email)
#puts email
mail = TMail::Mail.parse(email)
mail.parts.each do |part|
if ‘image/jpeg’ == part.content_type
part_type = part.content_type
part_body = part.body.base64_decode
filename = part.disposition_param(‘filename’)
puts part_type
puts "----- Separator -----"
puts part_body
puts "----- Separator ---"
puts filename
end
end
#~ #ticket = Ticket.new
#~ #ticket.from_email = email.from[0]
email.attachments.each do |attachment|
puts attachment
end
#mail.base64_decode
#new.receive(mail)
end
end
c:/ruby/lib/ruby/gems/1.8/gems/actionmailer-1.2.1/lib/action_mailer/vendor/tmail
/stringio.rb:125:in gets': undefined method
index’ for
#<TMail::Mail:0x334d4f8
(NoMethodError)
from
c:/ruby/lib/ruby/gems/1.8/gems/actionmailer-1.2.1/lib/action_mailer
/vendor/tmail/mail.rb:288:inparse_header' from c:/ruby/lib/ruby/gems/1.8/gems/actionmailer-1.2.1/lib/action_mailer /vendor/tmail/mail.rb:69:in
initialize’
from
c:/ruby/lib/ruby/gems/1.8/gems/actionmailer-1.2.1/lib/action_mailer
/vendor/tmail/mail.rb:68:inopen' from c:/ruby/lib/ruby/gems/1.8/gems/actionmailer-1.2.1/lib/action_mailer /vendor/tmail/port.rb:338:in
ropen’
from
c:/ruby/lib/ruby/gems/1.8/gems/actionmailer-1.2.1/lib/action_mailer
/vendor/tmail/mail.rb:68:ininitialize' from c:/ruby/lib/ruby/gems/1.8/gems/actionmailer-1.2.1/lib/action_mailer /vendor/tmail/mail.rb:54:in
new’
from
c:/ruby/lib/ruby/gems/1.8/gems/actionmailer-1.2.1/lib/action_mailer
/vendor/tmail/mail.rb:54:inparse' from receivePop.rb:11:in
receive’
from
c:/ruby/lib/ruby/gems/1.8/gems/actionmailer-1.2.1/lib/action_mailer
/base.rb:248:inreceive' from receivePop.rb:46 from receivePop.rb:44:in
open’
from receivePop.rb:44
from receivePop.rb:43:ineach' from c:/ruby/lib/ruby/1.8/net/pop.rb:528:in
each_mail’
from receivePop.rb:43
Any idea?..
Thanks,
Socheat Yi