0

我可以在通过同步和异步注册时通过 Sendgrid 发送/接收示例电子邮件,我只需将方法调用添加到注册控制器上的注册/创建中。

虽然我无法收到要发送的确认电子邮件,但它看起来像发送了,但我没有收到它,我能够收到我发送的样品。我现在正在本地做所有这些。

post transaction

Started POST "/users" for ::1 at 2021-01-28 22:59:54 -0600
Processing by Users::RegistrationsController#create as HTML
  Parameters: {"utf8"=>"✓", "authenticity_token"=>"xxx", "user"=>{"email"=>"email@gmail.com", "password"=>"[FILTERED]", "password_confirmation"=>"[FILTERED]"}, "commit"=>"Sign up"}
  [1m[35m (0.3ms)[0m  [1m[35mBEGIN[0m
  ↳ app/controllers/users/registrations_controller.rb:18:in `create'
  [1m[36mUser Exists? (0.7ms)[0m  [1m[34mSELECT 1 AS one FROM "users" WHERE "users"."email" = $1 LIMIT $2[0m  [["email", "email@gmail.com"], ["LIMIT", 1]]
  ↳ app/controllers/users/registrations_controller.rb:18:in `create'
  [1m[36mUser Create (0.6ms)[0m  [1m[32mINSERT INTO "users" ("email", "encrypted_password", "confirmation_token", "confirmation_sent_at", "created_at", "updated_at") VALUES ($1, $2, $3, $4, $5, $6) RETURNING "id"[0m  [["email", "email@gmail.com"], ["encrypted_password", "xxxx"], ["confirmation_token", "r-krQR4swLNVNaxWpN1w"], ["confirmation_sent_at", "2021-01-29 04:59:59.413152"], ["created_at", "2021-01-29 04:59:59.412987"], ["updated_at", "2021-01-29 04:59:59.412987"]]
  ↳ app/controllers/users/registrations_controller.rb:18:in `create'
  [1m[35m (0.4ms)[0m  [1m[35mCOMMIT[0m
  ↳ app/controllers/users/registrations_controller.rb:18:in `create'
  Rendering users/mailer/confirmation_instructions.html.erb
  Rendered users/mailer/confirmation_instructions.html.erb (Duration: 0.9ms | Allocations: 258)
  Rendering users/mailer/confirmation_instructions.html.erb
  Rendered users/mailer/confirmation_instructions.html.erb (Duration: 0.2ms | Allocations: 80)
SendGridApi::Email#confirmation_instructions: processed outbound mail in 11521.0ms
Delivered mail 6013965ae996c_175fe3fc53ffc5cbc46913@user-8888.cable.provider.com.mail (614.8ms)
Date: Thu, 28 Jan 2021 23:00:10 -0600
From: please-change-me-at-config-initializers-devise@example.com
Reply-To: please-change-me-at-config-initializers-devise@example.com
To: email@gmail.com
Message-ID: <6013965ae996c_175fe3fc53ffc5cbc46913@user-8888.cable.provider.com.mail>
Subject: Confirmation instructions
Mime-Version: 1.0
Content-Type: text/html;
 charset=UTF-8
Content-Transfer-Encoding: 7bit

<p>Welcome <email-addy>!</p>

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

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

Redirected to http://localhost:3000/
Completed 302 Found in 17300ms (ActiveRecord: 1.9ms | Allocations: 201325)


Started GET "/" for ::1 at 2021-01-28 23:00:11 -0600
Processing by HomeController#index as HTML
  Rendering home/index.html.erb within layouts/application
  Rendered home/index.html.erb within layouts/application (Duration: 0.2ms | Allocations: 69)
[Webpacker] Everything's up-to-date. Nothing to do
  Rendered users/shared/_links.html.erb (Duration: 0.7ms | Allocations: 309)
Completed 200 OK in 9ms (Views: 8.5ms | ActiveRecord: 0.0ms | Allocations: 4412)

对我来说,一切看起来都很好。

以下是一些其他相关的文件:

devise.rb

Devise.setup do |config|
  config.mailer_sender = 'please-change-me-at-config-initializers-devise@example.com'
  # config.mailer = 'Devise::Mailer'
  config.mailer = 'Email'
  require 'devise/orm/active_record'
  config.reconfirmable = true
end

lib/email.rb

# frozen_string_literal: true

class Email < Devise::Mailer

  helper :application
  include Devise::Controllers::UrlHelpers
  default template_path: 'users/mailer'
end

development.rb

  Rails.application.configure do

    config.action_mailer.default_url_options = { host: 'localhost', port: 3000 }
    config.action_mailer.delivery_method = :smtp

    ActionMailer::Base.smtp_settings = {
      port: 587,
      address: 'smtp.mailgun.org',
      domain: ENV['domain'],
      user_name: ENV['username'],
      password: ENV['password'],
      authentication: :plain
    }
  end

user.rb

class User < ActiveRecord::Base
  devise :database_authenticatable, :registerable,
         :recoverable, :rememberable, :validatable, :confirmable
end
4

0 回答 0