我尝试从生产环境向管理员发送电子邮件,但未能... 在开发中工作 letter opener gem
,但是当我尝试生产时,我收到以下错误:
Net::SMTPAuthenticationError (530-5.5.1 Authentication Required. Learn more at app/controllers/contact_us_controller.rb:8:in `submit_form'
app/models/contact_form.rb:13:in `send_admin_notification'
我在控制器中 submit_form操作的代码是:
def submit_form
@contact_form.attributes = contact_form_params
return redirect_to action: :thanks if @contact_form.save
render :index
end
contact_form模型中的代码为:
def send_admin_notification
AdminNotifier.contact_form(self).deliver_now
end
过去两天我一直在努力解决这个问题,所以任何帮助和指导都会非常感激
答案 0 :(得分:0)
这对我来说在生产环境中效果很好:
config.action_mailer.smtp_settings = {
:address => 'smtp.gmail.com',
:port => 587,
:domain => 'gmail.com',
:user_name => 'koshlendra@gmail.com',
:password => 'secret_password',
:authentication => 'login',
:enable_starttls_auto => true
}
答案 1 :(得分:0)
尝试将这些配置放在production.rb文件中
config.action_mailer.delivery_method = :smtp
config.action_mailer.default_url_options = { host:'yourhost'}
config.action_mailer.perform_deliveries = true
config.action_mailer.raise_delivery_errors = true
config.action_mailer.default :charset => "utf-8"
config.action_mailer.smtp_settings = {
:address => "smtp.gmail.com",
:port => 587,
:domain => 'gmail.com',
:user_name => "your email",
:password => "yourpassword",
:authentication => :plain,
:enable_starttls_auto => true
}