ruby-on-rails - 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 设置?
解决方案
推荐阅读
- c++ - arr[n] 是否在 C++ 中打印数组的长度?
- reactjs - 如何在地图上使用 react-semantic-ui transition.group
- variables - 更新 Azure DevOps 版本的变量组快照
- php - Sylius 添加管理页面
- mysql - 如何在没有自动增量的情况下增加 id?
- kubernetes - Kubernetes HPA 是如何工作的?
- javascript - 以编程方式启动的视频在 iPhone 上以空白打开(safari 和 chrome)
- java - resultactions 将 httpstatuscode 设置为特定值
- kendo-ui - 剑道饼图根据百分比值设置颜色
- asp.net - 抛出异常时,CORS 丢失