0

我已经设置了一个邮件拦截器,但我不能让它像我想要的那样复制电子邮件。

class MailDuplicator
  def self.delivering_email(message)

    copy = message
    copy.subject = "[Duplicata] To: #{message.to} - #{message.subject}"
    copy.to = "Logger <logs@email.com>"
    copy.deliver

    return message
  end
end

难道我做错了什么?

4

1 回答 1

1

找到了解决办法:不要使用mail_interceptor,而是使用mail_observer,邮件发送后调用。

# LIB (/lib/mail_duplicator.rb)
class MailDuplicator
  def self.delivered_email(message)
    duplicate_email = 'logs@email.com'

    if !message.to.include?(duplicate_email) # Avoid stack level too deep error
      message.subject = "[Duplicata] To: #{message.to} - #{message.subject}"
      message.to = duplicate_email

      message.deliver
    end

    return message
  end
end


# INITALIZER (/config/initializers/setup_mail.rb)
require 'mail_duplicator'
ActionMailer::Base.register_observer(MailDuplicator)

虽然我仍然没有Mail::Message像我最初想做的那样复制对象......

于 2013-10-16T16:00:55.093 回答