ActionMailer在后台发送电子邮件,queue_classic

时间:2014-03-14 04:08:52

标签: ruby-on-rails backgroundworker actionmailer queue-classic

我正在使用queue_classic
如何使用queue_classic发送以下电子邮件?

Notifier.welcome(david).deliver # sends the email

更新

我在User类

中添加了一个新的类方法
def.say_hello
  puts "hello!"
  Notifier.welcome(@david).deliver
end

QC.enqueue("puts", "hello world")工作正常,
QC.enqueue("User.say_hello")不发送电子邮件“
我该怎么办?

1 个答案:

答案 0 :(得分:1)

看起来像queue_classic' enqueue方法有两个参数:

  1. 致电方法
  2. 传递给此方法的参数
  3. 因此,您需要编写一个方法,您可以使用上面提供的两个项目来调用该方法。

    module QueueNotifier
      def self.send_welcome_email_to_user(id)
        user = User.find(id)
        Notifier.welcome(user).deliver
      end
    end
    

    然后,为了将这些发送事件排入队列,您将排队方法名称(QueueNotifier.send_email_to_user)和参数(无论用户ID为david还是您要发送给的用户)。

    QC.enqueue("QueueNotifier.send_welcome_email_to_user", 14)
    
相关问题