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

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
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?
This topic is locked and can not be replied to.