首页 > 解决方案 > Rail:为什么我会得到这个错误的参数,即 URI 对象或 URI 字符串错误

问题描述

application_mailer.rb - asys_delivery

def asys_delivery
  mail.delivery_method.settings = Rails.application.secrets.asys_smtp
end

asys_symtp 包含端口、域、用户名等设置。

internal_mailer.rb

class InternalMailer < ApplicationMailer
  include Rails.application.routes.url_helpers
  after_action :asys_delivery, only: %i[send_ops]

  def send_ops
    mail(from: 'my_mail@gmail.com',
      to: 'my_mail2@gmail.com',
      subject: params[:subject]
    )
  end
end

当我尝试使用此代码调用该方法时

InternalMailer.with(subject: "This is test subject").send_ops.deliver_now

我收到了这个错误

2.6.3 :003 > InternalMailer.with(subject: "This is test subject").send_ops.deliver_now
  Rendering internal_mailer/send_ops.html within layouts/mailer
  Rendered internal_mailer/send_ops.html within layouts/mailer (0.3ms)
InternalMailer#send_ops: processed outbound mail in 4.4ms
Sent mail to my_mail2@gmail.com (2.2ms)
Date: Mon, 28 Jun 2021 15:06:14 +0700
From: app.auditsystem@nutrifood.co.id
To: my_mail2@gmail.com
Message-ID: <60d982f6de3e1_779d2aff68ea997033946@LAPTOP-P2N1ECET.mail>
Subject: This is test subject
Mime-Version: 1.0
Content-Type: text/html;
 charset=UTF-8
Content-Transfer-Encoding: 7bit

<!DOCTYPE html>
<html>
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <style>
      /* Email styles need to be inline */
    </style>
  </head>

  <body>
    <%= @custom.html_safe %>
  </body>
</html>

Traceback (most recent call last):
        1: from (irb):3
ArgumentError (bad argument (expected URI object or URI string))
2.6.3 :004 >

另外,我正在使用 mailpy gem

编辑:现在我写了这个,我想知道当我使用 mailpy 而不是 smtp 时是否仍然需要设置 smtp 设置?

标签: ruby-on-railsrubyemailurimailer

解决方案


推荐阅读