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
corrupt.
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] =
File.read("#{Rails.root.to_s}/tmp/#{a.attachment_file_name}")
end
end
end
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?
on 2010-12-05 19:21
Please log in before posting. Registration is free and takes only a minute.
Existing account
(Switch to SSL-encrypted connection)
NEW: Do you have a Google/GoogleMail or Yahoo account? No registration required!
Log in with Google account | Log in with Yahoo account
Log in with Google account | Log in with Yahoo account
No account? Register here.