Forum: Ruby on Rails ActionMailer - Adding an attachment from S3

4efd15a59825388ea3382ec4d482a7d8?d=identicon&s=25 CuriousNewbie (Guest)
on 2010-12-05 19:21
(Received via mailing list)
Seems simple enough but I haven't been able to get it to work. The
files work fine from S3 on my web app, but when I email them out via
ActionMailer as attachments, see the code below, the files are

App Stack: rails 3, heroku, paperclip + s3

Here's the code:

    class UserMailer < ActionMailer::Base
    # Add Attachments if any
    if @comment.attachments.count > 0
      @comment.attachments.each do |a|
        require 'open-uri'
        open("#{Rails.root.to_s}/tmp/#{a.attachment_file_name}", "wb")
do |file|
          file << open(a.authenticated_url()).read
          attachments[a.attachment_file_name] ="#{Rails.root.to_s}/tmp/#{a.attachment_file_name}")

    mail( :to => "#{XXXX}",
          :reply_to => "XXXXX>",
          :subject => "XXXXXX"

a.authenticated_url() just gives me a URL to s3 to get the file (of
any type), I checked this, works fine. Something to do with the way
I'm saving the tempfile must be breaking the ActionMailer Attachment.

Any ideas?
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.