如何在Heroku上的生产环境的Rails应用程序中设置邮件程序

ban*_*ing 15 production ruby-on-rails actionmailer heroku devise

我需要使用邮件程序向用户发送电子邮件,将其密码设置为Devise和活动管理员的"可恢复"功能.在开发环境中,我通过在这些文件中添加以下内容来完成此操作:

配置/环境/发展

#Added per active admin install instructions
config.action_mailer.default_url_options = { :host => 'localhost:3000' }


#These settings are for the sending out email for active admin and consequently the   devise mailer
ActionMailer::Base.delivery_method = :smtp
ActionMailer::Base.perform_deliveries = true
ActionMailer::Base.raise_delivery_errors = true
ActionMailer::Base.smtp_settings = 
{

  :address            => 'smtp.gmail.com',
  :port               => 587,
  :domain             => 'gmail.com', #you can also use google.com
  :authentication     => :plain,
  :user_name          => 'XXXXX@gmail.com',
  :password           => 'XXXXXXX'
}
Run Code Online (Sandbox Code Playgroud)

如何为生产环境获得相同的功能?我想将我的应用程序部署到Heroku.我需要添加哪些文件和代码?

ste*_*eel 11

您在开发模式中设置的所有配置都将起作用,除非您需要重新配置默认邮件程序URL.

所以.

  1. 从development.rb复制粘贴您的设置.

  2. 将默认邮件程序指向您的heroku应用程序:

    config.action_mailer.default_url_options = { :host => 'YOURAPPNAME.herokuapp.com' }
    
    Run Code Online (Sandbox Code Playgroud)

此外,请注意您的smtp在转移到生产时可能具有的任何电子邮件限制.例如,在开发过程中很难触发gmail的smtp限制,但它们可能更容易在生产中触发.


ron*_*chn 4

如果它在开发模式下工作,那么它也会在生产模式下工作。

假设一切设置正确,在开发中重置密码将已经使用您的 Gmail 帐户发送一封实际的电子邮件。

设计仅依赖于正确的邮件程序配置设置(您已完成),并将设备配置为允许密码重置,以及可能的电子邮件“发件人”字段的另一个设置。

  • 是的,但是我应该在生产中为此添加什么: config.action_mailer.default_url_options = { :host => '??????' } (5认同)