use*_*821 8 heroku devise sendgrid ruby-on-rails-3.2
我有一个简单的Rails 3.2.7应用程序,添加了Devise,并添加了Sendgrid部署到Heroku.它可以在heroku上正常工作,除非需要进行密码检索,需要发送电子邮件.从我读过的所有帖子中我怀疑我以某种方式错误地设置了邮件参数.任何建议表示赞赏.
对于config/environments/production.rb,我添加了
config.action_mailer.default_url_options = { :host => 'smtp.sendgrid.net'}
Run Code Online (Sandbox Code Playgroud)
我添加了config/initializers/devise.rb
config.mailer_sender = "mail-to-send@from.com"
Run Code Online (Sandbox Code Playgroud)
对于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
}
Run Code Online (Sandbox Code Playgroud)
所以,你的问题是你引用了错误的环境变量.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
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
5930 次 |
| 最近记录: |