没有收到设计确认邮件

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

按照教程我将基本的rails应用程序添加用户身份验证。

有一个步骤,我必须将以下代码添加到setup_mail.rb文件

if Rails.env.development?
  ActionMailer::Base.delivery_method = :smtp
  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
  }
end

我添加了sendgrid插件,并将用户ID和密码也放在application.yml文件中。

但是当我注册时,我没有收到确认邮件。

交叉检查development.rb文件,并确保以下代码存在

....
   config.action_mailer.default_url_options = { host: 'localhost:3000' }
   config.action_mailer.delivery_method = :smtp
   config.action_mailer.perform_deliveries = true
end

遵循教程中的单词。因此真的很难过!谷歌把我指向了几个地方,让我更加困惑!

这就是我的迁移db文件目前的样子

class DeviseCreateUsers < ActiveRecord::Migration
  def change
    create_table(:users) do |t|
      ## Customization
       t.string :name
      ## Database authenticatable
      t.string :email,              null: false, default: ""
      t.string :encrypted_password, null: false, default: ""

      ## Recoverable
      t.string   :reset_password_token
      t.datetime :reset_password_sent_at

      ## Rememberable
      t.datetime :remember_created_at

      ## Trackable
      t.integer  :sign_in_count, default: 0, null: false
      t.datetime :current_sign_in_at
      t.datetime :last_sign_in_at
      t.string   :current_sign_in_ip
      t.string   :last_sign_in_ip

      ## Confirmable
       t.string   :confirmation_token
       t.datetime :confirmed_at
       t.datetime :confirmation_sent_at
       t.string   :unconfirmed_email # Only if using reconfirmable

      ## Lockable
      # t.integer  :failed_attempts, default: 0, null: false # Only if lock strategy is    :failed_attempts
  # t.string   :unlock_token # Only if unlock strategy is :email or :both
  # t.datetime :locked_at


  t.timestamps
end

add_index :users, :email,                unique: true
add_index :users, :reset_password_token, unique: true
# add_index :users, :confirmation_token,   unique: true
# add_index :users, :unlock_token,         unique: true
  end
end

这是我的user.rb文件

class User < ActiveRecord::Base
  # Include default devise modules. Others available are:
  # :confirmable, :lockable, :timeoutable and :omniauthable
  devise :database_authenticatable, :registerable,
         :recoverable, :rememberable, :trackable, :validatable, :confirmable
end

这些是我按顺序执行的步骤

  1. 安装设计宝石,跑bundle
  2. rails g devise:install
  3. 将以上代码添加到development.rb文件中
  4. rails g devise:views
  5. rails g devise User
  6. 在迁移文件`中取消注释confirmable
  7. rake db:migrate
  8. :confirmable添加到user.rb中的User类
  9. heroku addons:add sendgrid:starter
  10. heroku congif:get SENDGRID_USERNAME
  11. heroku config:get SENDGRID_PASSWORD
  12. 创建了config / initializers / setup_mail.rb并添加了上述邮件设置。
  13. 安装的figaro。
  14. 为application.yml文件添加了环境变量
  15. `figaro heroku:set -e production

更新

在development.rb中添加了邮件设置,没有运气。

尝试将域名从domain: 'heroku.com'更改为domain: 'sendgrid.com',没有运气。

这是服务器日志。邮件似乎已经发送但我无法在收件箱或垃圾邮件中找到它

Sent mail to [email protected] (2070.9ms)                                                                                                                                                    
Date: Wed, 07 Jan 2015 13:52:05 +0000                                                                                                                                                             
From: [email protected]                                                                                                                                  
Reply-To: [email protected]                                                                                                                              
To: myemailgmail.com                                                                                                                                                                        
Message-ID: <[email protected]>                                                                                                                            
Subject: Confirmation instructions                                                                                                                                                                
Mime-Version: 1.0                                                                                                                                                                                 
Content-Type: text/html;                                                                                                                                                                          
 charset=UTF-8                                                                                                                                                                                    
 Content-Transfer-Encoding: 7bit                                                                                                                                                                   

 <p>Welcome !</p>                                                                                                                                                            

<p>You can confirm your account email through the link below:</p>                                                                                                                                 

 <p><a href="http://localhost:3000/users/confirmation? confirmation_token=W3xuYfA8aq2obMBmffghfghQaDt">Confirm my account</a></p>                                                                          

   (45.0ms)  commit transaction                                                                                                                                                                   
Redirected to http://bloc-ruby-179559.apse1.nitrousbox.com/                                                                                                                                       
Completed 302 Found in 2872ms (ActiveRecord: 46.4ms)                                                                              
ruby-on-rails ruby heroku devise sendgrid
5个回答
5
投票

检查以确保Sendgrid没有暂停您的帐户。通过Heroku仪表板登录。然后点击你的应用。然后在插件下,单击Sendgrid。这将带您到他们的仪表板。如果有警告说您的帐户处于待审核状态,则必须与他们联系并让他们将其删除。


1
投票

您正在运行它以进行开发模式。形成的邮件可以在日志中看到但不能交付。默认情况下,它们不会以开发模式发送。要启用,请在development.rb中使用它

config.action_mailer.perform_deliveries = true

在config / environments / development.rb中使用以下代码

config.action_mailer.smtp_settings = {
    :address              => "smtp.sendgrid.net",
    :port                 => 587,
    :domain               => "sendgrid.com",   
    :user_name            => ""
    :password             => ""
    :authentication       => 'plain',
    :enable_starttls_auto => true  }
}

0
投票

在mail_setup.rb中,尝试将第一行更改为:

if Rails.env.development? || Rails.env.production?

0
投票

我和:confirmable遇到了同样的问题。我无法收到要发送的电子邮件,但我能够欺骗应用程序认为它已被发送并确认 - 因此登录。

:confirmable info

在控制台中:

User.find(1).confirm       # returns true unless it's already confirmed
User.find(1).confirmed?    # true/false
User.find(1).send_confirmation_instructions # manually send instructions

0
投票

在我的情况下,我使用我的gmail帐户与localhost环境,当我检查我的邮件,我显示谷歌的邮件说“登录尝试被阻止”由于“安全性较低的应用程序被阻止”,你可以启用它需要遵循mail link收到的指示

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