title: RUby - amazon S3 for remote url attachments - OpenURI::HTTPError: 403 Forbidden
body: <p>I know this question has been asked several times but none of the solutions provided work for me.
  I am using Ruby version 2.2.1 with open-uri and trying to add a remote url for my email attachments.</p>
  
  <p>What I have is:</p>
  
  <pre><code>@filename = "#{@doc.id}-#{@company.subdomain}-#{@doc.doc_number}-#{@doc.created_at.strftime("%Y-%m-%d")}.pdf"
  @file_path = "https://mybucket.s3.amazonaws.com/docs/doc_#{@doc.id}/#{@doc.filename}"
  
  attachments[@filename] = open(URI.parse("#{@file_path}")).read
  </code></pre>
  
  <p>I have also used </p>
  
  <pre><code> 1. File.read(open("#{@file_path}")
   2. open(Net::HTTP.get(URI.parse("#{@file_path}"))
   3. Added User-Agent
  </code></pre>
  
  <p>I removed URI.parse, tried with instance variable and without string interpolation. Nothing works. If I visit a file path on the browser it does work but not when I call it in my mailer.</p>
  
  <p>Any help would be much appreciated. </p>
  
  <p>EDIT:
  If I just hardcode a working url (no string interpolation) as a file attachment, it works fine.</p>