# ActionMailer

**URL:** <https://www.ruby-forum.com/t/actionmailer/139034>\
**Category:** Rails\
**Created:** [May 30, 2008, 8:59am UTC](https://www.ruby-forum.com/t/actionmailer/139034 "2008-05-30T08:59:36Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![wawa88](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/b5a626/32.png) [@wawa88](https://www.ruby-forum.com/u/wawa88)\
**Post date:** [May 30, 2008, 8:59am UTC](https://www.ruby-forum.com/t/actionmailer/139034/1 "2008-05-30T08:59:36Z")

</div>

Actually these code for receiving attachment is not working

if email.has\_attachments?  
for attachment in email.attachments  
page.attachments.create({  
:file =\> attachment, :description =\> email.subject  
})  
end

So i change the code to

if email.has\_attachments?  
email.attachments.each do |attachment|  
# save original file  
File.open(“C:/rubydev1/mail7/log/” +  
base\_part\_of(attachment.original\_filename)  
,File::CREAT|File::TRUNC|File::WRONLY,0666){ |f|  
f.write(attachment.read)  
f.close()  
}  
end  
end

And these code work fine, it did help me read the attachment file and  
save it into the ruby directory. Then now i want to retrieve the email  
header such as the receiver, the senter, subject and date. It is  
possible. Thanks

---

<div class="post-metadata">

**Author:** ![wawa88](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/b5a626/32.png) [@wawa88](https://www.ruby-forum.com/u/wawa88)\
**Post date:** [May 30, 2008, 11:22am UTC](https://www.ruby-forum.com/t/actionmailer/139034/2 "2008-05-30T11:22:30Z")

</div>

On May 30, 7:59 am, Emmie W. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> Actually these code for receiving attachment is not working
> 
> if email.has\_attachments?  
> for attachment in email.attachments  
> page.attachments.create({  
> :file =\> attachment, :description =\> email.subject  
> })  
> end  
> Assuming you’ve got the same models as the “other” person who posted  
> identical code a few days ago then file is a blob column in the  
> database and so you’d need :file =\> attachment.read.  
> email is a Tmail object so it’s full of methods for reading recipients  
> etc…

Fred
