Rails 3.0.7 ActionMailer attachments


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 = Time.now
@body = @email.body + “\n\n”

@email.attachments.each do |file|
  if File.exist?(file.full_path)
    attachment :filename => file.file_name,
                     :content => File.read(file.full_path),
                     :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] = File.read(file.full_path)

…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!