简体   繁体   中英

Rails Mailer issue with sending attchemnt over mail

I am migrating an application from Rails 2.3 to Rails 3.1, the emails are not working, when i send an email with attachment i see a plain/text email with the encoded pdf content in the email instead of as an attachment.

here is the command i used to send email

ret = UserMailer.return_forms(@customer[:email], @store, id, @customer[:document]).deliver

here is the definition of returns_form, the return_forms is a method in UserMailer class (class UserMailer < ActionMailer::Base)

  def return_forms(email, store, order, pdf_document_path)
    load_smtp_settings("noreply")
    @recipients = email
    @subject    = "#{business_name}: Return forms"
    @body       = "Please follow the instructions within the forms to return your merchandise. Thank You."
    attachments['free_book.pdf'] = {mime_type: 'application/pdf',content:  File.read(pdf_document_path) }
    @from       = email
    @date    = Time.zone.now
    @headers    = {}
  end

I see the content as

--
Date: Mon, 10 Aug 2015 16:16:26 +0530
Mime-Version: 1.0
Content-Type: text/plain;
 charset=UTF-8
Content-Transfer-Encoding: 7bit
Content-ID: <55c881028af96_48d43fe94782e9a0658aa@amol-desktop.mail>

Please follow the instructions within the forms to return your merchandise. Thank You.

--
Date: Mon, 10 Aug 2015 16:16:26 +0530
Mime-Version: 1.0
Content-Type: application/pdf;
 charset=UTF-8
Content-Transfer-Encoding: base64
Content-Disposition: attachment;
 filename=free_book.pdf
Content-ID: <55c88102872ba_48d43fe94782e9a0657a0@amol-desktop.mail>

JVBERi0xLjQKJcfsj6IKNyAwIG9iago8PC9MZW5ndGggOCAwIFIvRmlsdGVy
IC9GbGF0ZURlY29kZT4+CnN0cmVhbQp4nH1W227bOBB991cM0AWqABZLUvc8
bTZNivTiuLUX2GKzD6xE22pk0aWktOnX75CSbUW+xEhkDufMGc4cjvIDKGFA
zad7puvRmy8JLKuRtYJejnyfghd5MQRBSIGjTY4W1srDkB+xeh4HHocQ92yM
clxzr7NFLD6w7fx6WOtn4gWhD2ewjEfeaZIeuHW0GUYxg3Nwn/rhGaI+vnVt
8wzhHN4PqX+GqQ+3njbTxIez8DhOzhD14dZzUM+j8MD3zxH14K3nIOZReEjp

The return_forms call should have a call for mail() method at the end. Something like:

mail(:from => your_from, :to => your_to, :subject => your_subject, :body => your_body)

It is also a good idea to enable mailer errors in your development.rb to see if any errors appear:

config.action_mailer.raise_delivery_errors = true

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM