ruby-on-rails - Rails DeliveryJob 弃用警告 : How to upgrade to MailDeliveryJob?

标签 ruby-on-rails email actionmailer deprecation-warning

我有一个 Controller 操作,可以将电子邮件的发送排入队列。我为该 Controller 操作编写了一个测试,当我运行测试时,我收到了弃用警告:

DEPRECATION WARNING: Sending mail with DeliveryJob and Parameterized::DeliveryJob is deprecated and will be removed in Rails 6.1. Please use MailDeliveryJob instead.

Controller :

  def send_email
    SubscriptionMailer.with(user_id: @user.id).send_welcome_email.deliver_later
  end

SubscriptionMailer:

class SubscriptionMailer < ApplicationMailer
  helper :auxiliaries
  before_action { @user = User.find_by(id: params[:user_id]) }

  def send_welcome_email
    @base_email = find_base_email_or_raise("welcome_email")
    @subject = "#{@user.fname} #{@base_email.subject}"

    send_email(subject: @subject)
  end
end

测试:

  test "#send_email should enqueue SubscriptionMailer's #send_welcome_email" do
    assert_emails 1 do
      get send_email_admin_subscriptions_activation_path(
        @user.id,
      )
    end
  end

如何升级我的应用程序以消除警告?

我已经read about在不同帖子中取消注释 new_framework_defaults_6_0.rb 中的一行,但这并没有解决问题。

最佳答案

要修复弃用警告,请将此行添加到 application.rb:

config.action_mailer.delivery_job = "ActionMailer::MailDeliveryJob"

来源: https://github.com/rails/rails/issues/37068#issuecomment-545531362

问:这是否会影响电子邮件的传递方式?

该方法的参数已更改:

# DeliveryJob
def perform(mailer, mail_method, delivery_method, *args)

# MailDeliveryJob
def perform(mailer, mail_method, delivery_method, args:, params: nil)

因此,您可能必须在适用的情况下更改方法调用中的参数。

您可以找到有关此 PR 的更多详细信息:https://github.com/rails/rails/pull/34591

关于ruby-on-rails - Rails DeliveryJob 弃用警告 : How to upgrade to MailDeliveryJob?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/68638835/

相关文章:

ruby-on-rails - Gcloud、Ruby on Rails、语音转文本

ruby-on-rails - 找不到 RubyGem bundler

javax.activation.UnsupportedDataTypeException : no object DCH for MIME type multipart/mixed; boundary

java - 打开电子邮件客户端,并将 JFreeChart 的图表(图像)粘贴到正文中

ruby-on-rails - rails : Email a pdf generated with prawn to an email sent by ActionMailer?

ruby-on-rails - #<Array :> in ActiveAdmin row 的未定义方法 `name'

php - 附件名称和文件扩展名在电子邮件 *.eml 中不起作用

ruby-on-rails - Redmine 发送邮件两次

ruby-on-rails - 使用deliver_later时,邮件程序中无法访问attr_accessor

ruby-on-rails - 如何在 Rails 中测试文件上传以进行集成测试?