gpt4 book ai didi

ruby-on-rails - 发送电子邮件时测试失败 : An SMTP To address is required to send a message. 设置邮件 smtp_envelope_to、to、cc 或 bcc 地址

转载 作者:行者123 更新时间:2023-12-04 05:53:21 25 4
gpt4 key购买 nike

我有一个用户模型的 after_create 回调,它将向管理员发送一封电子邮件,以便他可以批准该帐户。它在开发模式下完美运行,但是当我运行 Capybara/RSpec 测试时,它失败并出现以下异常:

ArgumentError:
An SMTP To address is required to send a message. Set the message smtp_envelope_to, to, cc, or bcc address.

我确实在 config/environments/test.rb 中将 config.action_mailer.delivery_method 设置为 :test 。为什么它在测试环境中尝试使用 SMTP?为什么仅此电子邮件交付(在模型中)会发生这种情况,而其他交付(使用 devise gem)不会发生这种情况?

这是用户模型的一个片段:
class User < ActiveRecord::Base
after_create :send_admin_mail
protected

def send_admin_mail
puts ActionMailer::Base.delivery_method #prints test!
ReviewMailer.new_user_waiting_for_approval(self).deliver
end
end

最佳答案

尝试设置:

config.action_mailer.raise_delivery_errors = false

在您的 test.rb 文件中,如果它不存在,请添加它。

关于ruby-on-rails - 发送电子邮件时测试失败 : An SMTP To address is required to send a message. 设置邮件 smtp_envelope_to、to、cc 或 bcc 地址,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20331248/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com