# TMail + Receing mail and extract attachments

**URL:** <https://www.ruby-forum.com/t/tmail-receing-mail-and-extract-attachments/97247>\
**Category:** Rails\
**Created:** [July 5, 2006, 10:43pm UTC](https://www.ruby-forum.com/t/tmail-receing-mail-and-extract-attachments/97247 "2006-07-05T22:43:45Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Socheat\_Yi](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/54ee81/32.png) [@Socheat\_Yi](https://www.ruby-forum.com/u/Socheat_Yi)\
**Post date:** [July 5, 2006, 10:43pm UTC](https://www.ruby-forum.com/t/tmail-receing-mail-and-extract-attachments/97247/1 "2006-07-05T22:43:45Z")

</div>

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](http://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:in `parse_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:in `open' 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:in `initialize' 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:in `parse' 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:in `receive' from receivePop.rb:46 from receivePop.rb:44:in `open’  
> from receivePop.rb:44  
> from receivePop.rb:43:in `each' from c:/ruby/lib/ruby/1.8/net/pop.rb:528:in `each\_mail’  
> from receivePop.rb:43

Any idea?..

Thanks,  
Socheat Yi

---

<div class="post-metadata">

**Author:** ![Socheat\_Yi](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/54ee81/32.png) [@Socheat\_Yi](https://www.ruby-forum.com/u/Socheat_Yi)\
**Post date:** [June 26, 2009, 4:09pm UTC](https://www.ruby-forum.com/t/tmail-receing-mail-and-extract-attachments/97247/2 "2009-06-26T16:09:22Z")

</div>

did you ever figure out what was giving you the error? I’m hitting the  
exact same thing when trying to test my mailer model.
