mikel/mail — Issue #291: Attaching a Tempfile
Author: xavierRiley
Created: 2011-10-11 10:18:51+00:00
State: open

Hi,
I've been struggling with this for a little while. Tried various things but nothing working as yet.

I have a form on a site that is emailed straight to another user.
I've tried the following;

add_file :filename => file_uploads[0][:filename], :content => File.read(file_uploads[0][:tempfile]), :content_type => file_uploads[0][:type] + "; filename=\"#{Mail::Encodings.decode_encode file_uploads[0][:filename].to_s, :encode}\""

Where file_uploads[0] is the following Hash;

{:filename=>"todo.txt", :type=>"text/plain", :name=>"doc_1", :tempfile=>#, :head=>"Content-Disposition: form-data; name=\"doc_1\"; filename=\"todo.txt\"\r\nContent-Type: text/plain\r\n"}

With this I get the following error;

undefined method `string' for nil:NilClass
file: parts_list.rb
location: get_order_value
line: 44

So basically, despite setting the content type explicity, it's getting ignored when it gets to line 44 of parts_list.rb (included here for reference)

def get_order_value(part, order)
if part.respond_to?(:content_type)
order.index(part[:content_type].string.downcase) || 10000
else
10000
end
end

Is there a tried and tested way to attach a Tempfile? Am I just being stupid?
Env stuff = Padrino 10.1 app, ruby 1.9.2p290, mail 2.3.0

Thanks,