Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Invalid filename in email (ActionMailer)

I have a trouble with sending email message with attachment using ActionMailer.

The thing is my attachment has 'noname' filename when I reading my message in gmail.

Notifier function

class Notifier < ActionMailer::Base
  def send_message
    attachments["text.txt"] = {:content => "hello"}
    mail(:to => "[email protected]", :subject => 'test')
  end
end

Message headers:

Date: Sun, 19 Dec 2010 23:18:00 +0100
Mime-Version: 1.0
Content-Type: text/plain;
 charset=UTF-8;
 filename=text.txt
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment;
 filename=text.txt
Content-ID: ...

How can I send a message with right filename?

Thanks

like image 676
Kirill Avatar asked Feb 03 '23 23:02

Kirill


2 Answers

Make sure you have your views.

Make the correct files in app/views/[class_name]/[method_name]
Create a app/views/notifier/send_message.erb file and app/views/notifier/send_message.html.erb file.

like image 154
Drew LeSueur Avatar answered Feb 13 '23 17:02

Drew LeSueur


Drew is right, this problem occur if specific mailer view is missing.

IMHO, gmail does not get the encoding of message and renames attachments.

More info is available in Gmail help:

  • http://mail.google.com/support/bin/answer.py?answer=9524

  • http://mail.google.com/support/bin/answer.py?hl=en&answer=10290

like image 40
bmihelac Avatar answered Feb 13 '23 15:02

bmihelac