Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3723888
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T06:26:22+00:00 2026-05-19T06:26:22+00:00

Seems simple enough but I haven’t been able to get it to work. The

  • 0

Seems simple enough but I haven’t been able to get it to work. The files work fine from S3 on the web app, but when I email them out via 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?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-19T06:26:24+00:00Added an answer on May 19, 2026 at 6:26 am

    This might work better because it doesn’t touch the filesystem (which is often problematic on Heroku):

    require 'net/http'
    require 'net/https' # You can remove this if you don't need HTTPS
    require 'uri'
    
    class UserMailer < ActionMailer::Base
      # Add Attachments if any
      if @comment.attachments.count > 0
        @comment.attachments.each do |a|
          # Parse the S3 URL into its constituent parts
          uri = URI.parse a.authenticated_url
          # Use Ruby's built-in Net::HTTP to read the attachment into memory
          response = Net::HTTP.start(uri.host, uri.port) { |http| http.get uri.path }
          # Attach it to your outgoing ActionMailer email
          attachments[a.attachment_file_name] = response.body
        end
      end
    end
    

    I don’t think this will cause any extra memory issues because in any case you have to load the file’s data into memory on the attachments[a.attachment_file_name] line.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

That seems simple enough, but all Django Queries seems to be 'SELECT *' How
this seems like a simple enough question but I can't seem to find a
Seems simple, but not for me. I can get the current year with: <jsp:useBean
Seems simple enough, but I cannot figure out any way to determine what the
I'm trying to preview a file with UIDocumentInteractionController. Seems simple enough but randomly the
This seems simple enough, but I'm stuck. I have a View Controller that respondes
I am new to JavaScript. This request seems simple enough but cant seem to
This seems simple enough, but I can't seem to find the setting in Eclipse
This should seem simple enough, but can't figure it out. I was porting a
Seems simple enough. I'm creating a search engine that returns results to the user

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.