我有一个简单的 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/