【问题标题】:How to configure Devise email with Heroku and Sendgrid in Rails?如何在 Rails 中使用 Heroku 和 Sendgrid 配置设计电子邮件?
【发布时间】:2013-04-25 19:12:42
【问题描述】:

我有一个添加了 Devise 的简单 Rails 3.2.7 应用程序,它部署到 Heroku 并添加了 Sendgrid。它在 heroku 上运行良好,除非它需要进行密码检索,这需要发送电子邮件。从我读过的所有帖子中,我怀疑我以某种方式错误地设置了邮件参数。任何建议表示赞赏。

对于我添加的 config/environments/production.rb

config.action_mailer.default_url_options = { :host => 'smtp.sendgrid.net'} 

我添加了 config/initializers/devise.rb

config.mailer_sender = "mail-to-send@from.com"

对于 config/environments.rb 我添加了

ActionMailer::Base.smtp_settings = {
:address        => 'smtp.sendgrid.net',
:port           => '587',
:authentication => :plain,
:user_name      => ENV['SENDGRID_USERNAME'],
:password       => ENV['SENDGRID_PASSWORD'],
:domain         => 'heroku.com',
:enable_starttls_auto => true
}

【问题讨论】:

    标签: heroku devise ruby-on-rails-3.2 sendgrid


    【解决方案1】:

    所以,您的问题是您引用了错误的环境变量。 Heroku 将您的 SendGrid 凭据存储在 ENV['SENDGRID_USERNAME']ENV['SENDGRID_PASSWORD'] 中。您使用您的实际用户名和密码作为密钥名称。

    这将起作用:

    ActionMailer::Base.smtp_settings = {
      :address        => 'smtp.sendgrid.net',
      :port           => '587',
      :authentication => :plain,
      :user_name      => ENV['SENDGRID_USERNAME'],
      :password       => ENV['SENDGRID_PASSWORD'],
      :domain         => 'heroku.com',
      :enable_starttls_auto => true
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-04-01
      • 2014-09-09
      • 1970-01-01
      • 1970-01-01
      • 2019-05-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多