Rails设计中出现Gmail错误

Man*_*der 2 ruby-on-rails actionmailer devise

我目前正在使用带有邮件系统的应用程序。它工作正常,发送了一封欢迎电子邮件并发送了重置密码的说明,但是现在并且只有当我尝试发送重置说明时,我才出现此错误。

ArgumentError (SMTP From address may not be blank: nil):
Run Code Online (Sandbox Code Playgroud)

我正在使用这样的自定义域noreply@mycustomdomain.com ,这是我的配置

development.rb

 config.action_mailer.raise_delivery_errors = true
 config.action_mailer.perform_caching = false
 config.action_mailer.default_url_options = { host: 'localhost:3000' }

 config.action_mailer.delivery_method = :smtp
 config.action_mailer.smtp_settings = {
     address: 'smtp.gmail.com',
     port: '587',
     domain: 'gmail.com',
     authentication: :plain,
     enable_starttls_auto: true,
     user_name: Rails.application.secrets.mailer_username,
     password: Rails.application.secrets.mailer_password
}
Run Code Online (Sandbox Code Playgroud)

任何的想法 ?

编辑

class UserMailer < ApplicationMailer
  default from: 'noreply@mycustomdomain.com'

  def welcome_email(user)
    @user = user
    @url = 'http://localhost:3000/users/sign_in'
    mail(to: @user.email, subject: 'Bienvenue')
  end

  def generate_new_password_email
    user = User.find(params[:user_id])
    user.send_reset_password_instructions
  end

  def reset_password; end
end
Run Code Online (Sandbox Code Playgroud)

小智 5

您可以使用以下default_option尝试在配置中设置:from

config.action_mailer.default_options = { from: 'noreply@mycustomdomain.com' }
Run Code Online (Sandbox Code Playgroud)


Som*_*rma 1

我遇到了同样的问题,其背后的原因是我在开发中工作,但我的邮件程序正在生产中搜索 smtp_settings ,因此要解决该问题,您可以更改邮件程序设置,或者可以将相同的 smtp_settings 复制到生产中。