Forum: Ruby on Rails Rails 3.0.7 ActionMailer attachments

Af520b18a7666a48d9f8ff7f040f9eb1?d=identicon&s=25 crunch (Guest)
on 2011-05-24 23:18
(Received via mailing list)

I'm converting my 2.3.8 application to 3.0.7 and have run into a snag
with forwarding emails from the app with an attachment. The attachment
appears in the email as 1 byte in size and thus corrupt. The actual
file is fine and Rails seems to have access to the file. I've tried
multiple permutations but here's what I'm doing...

I'm fetching email from IMAP and storing it in the db. Attachments are
saved to the file system and the Attachment model stores the name of
the attachment and belongs to an Email. In the view there's a simple
form that allows an email address to forward the email to. That's all
working fine. It's just the attachment part that I'm having troubles

def forward_email(email_id, from_address, to_address)
    @email = Email.find(email_id)
    @recipients = to_address
    @from = from_address
    @subject = @email.subject
    @sent_on =
    @body = @email.body + "\n\n"

    @email.attachments.each do |file|
      if File.exist?(file.full_path)
        attachment :filename => file.file_name,
                         :content =>,
                         :content_type => "application/octet-stream"
        @body += "ATTACHMENT NOT FOUND: #{file.file_name}\n\n"

If I try the attachment part like this...

attachments[file.file_name] =

...then I get a text representation of the attachment at the bottom of
the email. I've also tried changing many different settings for
content_type but it doesn't seem to make a difference.

Any help would be much appreciated!


Please log in before posting. Registration is free and takes only a minute.
Existing account

NEW: Do you have a Google/GoogleMail, Yahoo or Facebook account? No registration required!
Log in with Google account | Log in with Yahoo account | Log in with Facebook account
No account? Register here.