I am trying to send PDF attachments to one of my rail applications, but the application appears as text, and not as the correct pdf.
My mail is as follows:
class Notifications < ActionMailer::Base def contact(email_params, sent_at = Time.now) subject "" << email_params[:subject] recipients "" << email_params[:client] from "#{email_params[:name]} <#{email_params[:address]}>" attachments['invoice.pdf'] = File.read("#{Rails.root.to_s}/public#{email_params[:attach]}") unless email_params[:attach].blank? sent_on sent_at body :message => email_params[:body], :sender_name => email_params[:name] end end
And what I get in my inbox:
-- Date: Thu, 23 Feb 2012 13:50:58 -0800 Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit Content-ID: <[mailserver]> Message Body -- Date: Thu, 23 Feb 2012 13:50:58 -0800 Mime-Version: 1.0 Content-Type: application/pdf; charset=UTF-8; filename=invoice.pdf Content-Transfer-Encoding: base64 Content-Disposition: attachment; filename=invoice.pdf Content-ID: <[mailserver]>
Following a very long string of ascii characters
Without any attachment, this header information is not sent, and I just get the โMessage Bodyโ part in my inbox. I suspect that part of the File.read () file in the attachment line in my mailbox is somehow the culprit, but it points to a valid pdf file on my server that I can access through my browser. The logs only say that the mail was sent with the correct parameters, but it is sent as what looks like decompiled text or something like if you opened the PDF in a text editor.
In the mail view, contact.html.erb is simple: <%= @message %> If that helps.
Any idea what I can do wrong?
Thanks.
Update:
Apparently I needed both contact.erb and contact.html.erb in my views directory. Just copying the file and renaming it worked. However, the message body is now empty. Only the application appears.
source share