heroku - 如何在 Rails 中使用 Heroku 和 Sendgrid 配置设计电子邮件?

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

我有一个简单的 Rails 3.2.7 应用程序,添加了 Devise,它部署到 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 将您的 SendGrid 凭据存储在 ENV['SENDGRID_USERNAME'] 中和 ENV['SENDGRID_PASSWORD'] .您使用的是您的实际用户名和密码作为 key 名称。

这将起作用:

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 - 如何在 Rails 中使用 Heroku 和 Sendgrid 配置设计电子邮件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16222885/

相关文章:

ruby-on-rails - 无法将 Rails 应用程序部署到 Heroku

mysql - rails 数据库 :migrate fails '[MODEL].users' doesn't exist: SHOW FULL FIELDS FROM `users`

ruby-on-rails - Devise token_authenticatable 已弃用,替代方案是什么?

Javascript window.open 返回未定义

git - 将 Heroku 与 git repo 同步的最佳方式?

ruby-on-rails - rails : heroku run console giving error "bash: console: command not found"

node.js - 在heroku上的node.js中追加文件

ruby-on-rails - 使用设备未收到确认邮件

activerecord - I18n::Backend::ActiveRecord 范围

ruby-on-rails - rails : Has_many through query depending on the through table attribute