我目前正在使用邮件系统开发一个应用程序。它工作正常,发送欢迎电子邮件并发送重置密码的说明,但现在且仅当我尝试发送重置说明时,我才会遇到此错误。
ArgumentError (SMTP From address may not be blank: nil):
我正在使用像这样的自定义域
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
}
任何想法 ?
编辑
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
最佳答案
我遇到了同样的问题,其背后的原因是我在开发中工作,但我的邮件程序正在生产中搜索 smtp_settings,因此要解决此问题,您可以更改邮件程序设置,或者您可以将相同的 smtp_settings 复制到生产中。
关于ruby-on-rails - Rails 设计有 gmail 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45014520/