我有超级简单的邮件:
class Mailer < ActionMailer::Base
def welcome_email(email)
@email = email
mail to: email, subject: "[#{I18n.t 'email_subject_welcome'}"
end
end
但是当我使用example@gmail.com
运行测试时出现此错误:
An SMTP To address is required to send a message. Set the message smtp_envelope_to, to, cc, or bcc address.
这里应该做什么?
答案 0 :(得分:1)
你是如何在Rspec中实际调用它的?发布该代码,如果你尚未弄清楚它。听起来像变量电子邮件是零。
答案 1 :(得分:1)
由于拦截器而发生问题:
class SandboxEmailInterceptor
def self.delivering_email(message)
message.to = Rails.application.secrets.your_email
end
end
ActionMailer::Base.register_interceptor(SandboxEmailInterceptor) unless Rails.env.production?
secrets.yml
有your_email: <%= ENV["YOUR_EMAIL"] %>
,application.yml
电子邮件丢失。