Devise + Sendgrid确认-Ruby on Rails

问题描述 投票:0回答:1

因此,我正在尝试为此应用设置电子邮件确认,到目前为止,我几乎已经掌握了它。它在开发中(使用sendgrid)工作得很好,但在生产中却没有。它只是在生产中出错。我已经设置了配置环境(通过我具有sendgrid API集成的帐户),我遵循了许多使用SMTP方法和WebAPI的教程。没有任何工作。我尝试在rb文件上使用bundle exec执行测试消息,效果很好。确认代码很好,电子邮件正在开发中(本地环境),但是我仅在发送产品确认电子邮件时才发现问题。该页面本身将让我知道电子邮件是否有错误,或者是否已经使用了电子邮件,但仅在发送电子邮件时才会出错。这告诉我电子邮件代码很好,我的API集成有问题。这是代码:

./ Environments / production.rb:

config.action_mailer.delivery_method = :smtp
config.action_mailer.default_url_options = { :host => 'bryan-saas-app.herokuapp.com', :protocol => 'https' }

./ Initializers / devise.rb:

config.mailer_sender = '[email protected]'

./ 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

}

./ sendgrid.env:

export SENDGRID_API_KEY='full api key'
export SENDGRID_USERNAME='apikey'
export SENDGRID_PASSWORD='full api key'

我想念什么吗?就其价值而言,我无法从仪表板的heroku app / config.add-ons区域访问我的sendgrid帐户。它在那里也出错,所以我创建了一个新的sendgrid帐户(个人,非heroku链接)并从那里使用了API代码。不知道这是否会破坏某些东西。

ruby-on-rails sendgrid
1个回答
0
投票

Sendgrid与您的开发环境无关。

控制台:

heroku addons:create sendgrid:starter

application_mailer.rb:

  #replace corsego with your app name
  default from: '[email protected]'

production.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 
}

environment.rb:

      #replace corsego with your app name
      config.action_mailer.default_url_options = { :host => 'corsego.herokuapp.com', :protocol => 'https' }
      config.action_mailer.perform_deliveries = true
      config.action_mailer.delivery_method = :smtp

文档:https://devcenter.heroku.com/articles/sendgrid

将更改推送到生产中,就可以使用sendgrid。

这里将逐步确认可确认的设备https://github.com/heartcombo/devise/wiki/How-To:-Add-:confirmable-to-Users

© www.soinside.com 2019 - 2024. All rights reserved.