发送邮件需要SMTP To地址。设置消息smtp_envelope_to,to,cc或bcc地址

时间:2014-07-12 22:37:04

标签: ruby-on-rails ruby email rspec

我有超级简单的邮件:

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.

Email is present

这里应该做什么?

2 个答案:

答案 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.ymlyour_email: <%= ENV["YOUR_EMAIL"] %>application.yml电子邮件丢失。