Reputation: 5214
Am using rails 3.0.7 & Mail (gem) 2.2.19.
When I try to send the email with attachments, Instead of showing up as a downloadable attachment, I rather get the attachment as plain-text in the email.
I have
attachments["example.png"] = File.read("path to image file")
I also tried
attachments["rails.png"] = {:content=>File.read("#{Rails.root}/public/images/rails.png"),
:mime_type=>"images/png"}
none of the above worked.
Can some one help me out of this mire.
Upvotes: 2
Views: 466
Reputation: 2959
I had the same problem, and in my case the solution was to swap the attachment and mail lines. First attach, then call mail.
WRONG
def pdf_email(email, subject, pdfname, pdfpath)
mail(:to => email, :subject => subject)
attachments[pdfname] = File.read(pdfpath)
end
GOOD
def pdf_email(email, subject, pdfname, pdfpath)
attachments[pdfname] = File.read(pdfpath)
mail(:to => email, :subject => subject)
end
Upvotes: 1