Forum: Ruby on Rails body of email not displaying with attachments in rails2.3.5

Ecec81af7caddc8730eee285475df4da?d=identicon&s=25 ruby rails (rubyonrails)
on 2013-09-29 09:11
I am sending an email through my application to other user's gmail id. I
am receiving email and it works fine without attachment. But when I
attach a file, the mail which users receive contain subject and
attachments only. The body part is not displaying in the mail. In the
controller I am passing everything as params to reminder_email method. I
am using rails2.3.5..This is how I have implemented in my mailer.rb
file. Please help.

    class ReminderMailer < ActionMailer::Base

      def reminder_email(sender,recipients, subject,
message,attachments)
        recipient_emails = (recipients.class == String) ?
recipients.gsub(' ','').split(',').compact : recipients.compact
        setup_reminder_email(sender, recipient_emails, subject,
message,attachments)
      end

      protected
      def setup_reminder_email(sender, emails, subject, message,files)
        @from = sender
        @recipients = emails
        @subject = subject
        @sent_on = Time.now
        @body['message'] = message
        #content_type =  "multipart/alternative"
         files.each do |file|
          attachment "application/octet-stream" do |a|
          a.body = file.read
          a.filename = file.original_filename
        end unless file.blank?
        end
      end
    end
B2d0e18bbe76b82a2772c182f5d46729?d=identicon&s=25 vikram j. (vikram_j)
on 2013-09-30 06:35
(Received via mailing list)
def email_with_attachments(application_fields={},files=[])
  @headers = {}
  @sent_on = Time.now
  @recipients = 'client@domain.com'
  @from = 'info@domain.com'

  @subject = 'Here are some file attachments'
  application_fields.keys.each {|k| @body[k] = application_fields[k]}

  # attach files
  files.each do |file|
    attachment "application/octet-stream" do |a|
      a.body = file.read
      a.filename = file.original_filename
    end unless file.blank?
  end
end


On Sun, Sep 29, 2013 at 12:41 PM, ruby rails <lists@ruby-forum.com>
wrote:

>       def reminder_email(sender,recipients, subject,
>         @recipients = emails
>       end
> To post to this group, send email to rubyonrails-talk@googlegroups.com.
> To view this discussion on the web visit
>
https://groups.google.com/d/msgid/rubyonrails-talk...
> .
> For more options, visit https://groups.google.com/groups/opt_out.
>



--
Thanks & Regard
   Vikram Jain
=============
Please log in before posting. Registration is free and takes only a minute.
Existing account

NEW: Do you have a Google/GoogleMail, Yahoo or Facebook account? No registration required!
Log in with Google account | Log in with Yahoo account | Log in with Facebook account
No account? Register here.