Jump to content

The ultimate community for Ruby on Rails developers.


Photo

Email body text being repeated for each attachment


  • Please log in to reply
1 reply to this topic

#1 nexar

nexar

    Passenger

  • Members
  • 2 posts

Posted 17 March 2014 - 11:08 AM

I have the following Action Mailer :

def sendinvoicesemail(eminvs,emref)

    @client = Client.find(eminvs[0].invclientid)

    recipients = ''

    3.times do |num|

      recipients += eval('@client.clientemail'+(num + 1).to_s) + ',' if eval('@client.clientinvemail' + (num + 1).to_s) == true

    end

    fpath = AppParam.val('SITEBASEADDR')+'/public/invs/'

    eminvs.each do |inv|

      fname = inv.invsuppjoinedname+'_'+inv.invno.to_s+'.pdf'

      mail.attachments[fname] = File.read(fpath+fname)

    end

    mail(

        :to => recipients,

        :from => "GourmIndia  Services GmbH Group<purvez@nexar.free-online.co.uk>",

        :subject => "Invoices from GourmIndia Group / " + emref.to_s

        #:sent_on => Time.now

    )

  end

And the following Client method

  def self.sendinvoicesemail

    emref = AppParam.val('EMAILREF').to_i

    externalclients.each do |cl|

      eminvs = cl.invoices.emailable

      next if eminvs.length == 0

      emref += 1

      Clientmailer.sendinvoicesemail(eminvs,emref).deliver

      AppParam.set("EMAILREF",emref)

     end

  end

And the following body text in : 'sendinvoicesemail.html.erb'

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

    <html>

        <head>

            <meta content="text/html; charset=UTF-8" http-equiv="Content-Type" />

        </head>

        <body>

            <p>

                Attached to this email you will find invoices for services recently supplied by GourmIndia Group Companies.

            </p>

            <p>

                Please ensure that you pay in the correct currency, into the correct account and within <%= @client.clientcreditdays.to_s %> days from invoice date as per our agreement.

            </p>

            <p>

                Thank you for booking with GourmIndia Group.

            </p>

        </body>

    </html>

The body text gets repeated for each attachment.

 

Please can someone tell me what I'm doing wrong.

 

I'm using Rails v3.2.1.

 

Thanks in advance

 

 

 



#2 nexar

nexar

    Passenger

  • Members
  • 2 posts

Posted 17 March 2014 - 03:51 PM

SOLUTION:

Within Clientmailer I changed the line:

mail.attachments[fname] = File.read(fpath+fname)

to

attachments[fname] = File.read(fpath+fname)

I don't fully understand why this should be so if anyone can throw some light on this it would be useful.






0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users