0

我正在使用 resque_mailer 从我的应用程序发送电子邮件。这是我的邮件类:

class BulkMailer < ActionMailer::Base
  include Resque::Mailer
  default from: XXXX,
          reply_to: XXXXXX


  def bulk_email(email_id)

    @email = Email.find(email_id)

    recipients = @email.recipients.split(',')
    # => @email.recipients='sss@sss.com,sss@abc.com'

    smtp_header = {
      'to'=> recipients,

      'filters'=> {
        'opentrack' => {
          'settings'=> {
            'enable'=> 1
          }
        }
      },

      'category' => @email.subject
    }

    headers["X-SMTPAPI"] = smtp_header.to_json

    mail(to: 'cccc@ddd.com', subject: @email.subject)

  end
end

我正在使用 Sendgrid 的 SMTP API。

当我使用 normail 同步邮件时,一切都很好。但是,当我在此类中使用包含语句启用 resque 邮件程序时,我在 resque-web 中收到一条失败消息。

它说:

undefined method `recipients' for 48:Fixnum
/home/steve/dev/rails/jm-sub/app/mailers/bulk_mailer.rb:9:in `bulk_email'
/var/lib/gems/1.9.1/gems/actionpack-3.2.13/lib/abstract_controller/base.rb:167:in `process_action'
/var/lib/gems/1.9.1/gems/actionpack-3.2.13/lib/abstract_controller/base.rb:121:in `process'
/var/lib/gems/1.9.1/gems/actionpack-3.2.13/lib/abstract_controller/rendering.rb:45:in `process'
/var/lib/gems/1.9.1/gems/actionmailer-3.2.13/lib/action_mailer/base.rb:459:in `process'
/var/lib/gems/1.9.1/gems/actionmailer-3.2.13/lib/action_mailer/base.rb:453:in `initialize'
/var/lib/gems/1.9.1/gems/resque_mailer-2.2.4/lib/resque_mailer.rb:48:in `new'
/var/lib/gems/1.9.1/gems/resque_mailer-2.2.4/lib/resque_mailer.rb:48:in `perform'

这就是我调用邮件程序的方式: BulkMailer.bulk_email(email.id).deliver

同样,它无需resque即可工作。我不知道怎么了。。

4

1 回答 1

0

My bad. :) I hadnt restarted the Resque workers after updating the code.

Restarting rails server didnt do the trick.

于 2013-06-29T14:27:11.413 回答