Forum: Ruby on Rails Sending email with attachment

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
CiriusMex (Guest)
on 2011-01-28 03:14
(Received via mailing list)
Hello, I'm trying to create a function to send mail with an attached
file. After an hour reading rails documentation and a few intents I
can't figure out this error:

undefined local variable or method 'attachments' for Emailer:Class

Here comes the code of the mail creation function:

class Emailer < ActionMailer::Base
   def Emailer.sendMailBCCWithAttachments(recipient, subject, message,
from, newsletter)
       attachments[newsletter.filename] ="#{RAILS_ROOT}/

         :subject => subject,
         :bcc => recipient,
         :from => from,
         :content_type => "text/html; charset=utf-8",
         :body => message,
         :sent_on =>

And here is how I use it:
# Create the mail
mail = Emailer.sendMailBCCWithAttachments(recipients,
newsletter.subject, message, "", newsletter)
# Sends it

Any idea?
Matt Jones (Guest)
on 2011-01-28 23:24
(Received via mailing list)
On Jan 27, 9:13pm, CiriusMex <> wrote:
>  def Emailer.sendMailBCCWithAttachments(recipient, subject, message,
> from, newsletter)

Haven't used the 3.0 ActionMailer much yet, but the docs say that
sendMailBCCWithAttachments (and seriously, this isn't Java -
underscores FTW! :) ) shouldn't be a class method, but rather an
instance method (lose the 'Emailer.' part).

--Matt Jones
This topic is locked and can not be replied to.