简体   繁体   中英

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

I have super simple mailer:

class Mailer < ActionMailer::Base
  def welcome_email(email)
    @email = email
    mail to: email, subject: "[#{I18n.t 'email_subject_welcome'}"
  end
end

but when I run tests with example@gmail.com I get this error:

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

电子邮件存在

What should be done here?

How are you actually calling it in Rspec? post that code if you haven't figured it out yet. It sounds to me like the variable email is nil.

The problem occurred because of interceptor:

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?

Where secrets.yml has your_email: <%= ENV["YOUR_EMAIL"] %> , and my application.yml whith email was missing.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM