質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.48%
Devise

Deviseとは、Ruby-on-Railsの認証機能を追加するプラグインです。

Ruby on Rails 4

Ruby on Rails4はRubyによって書かれたオープンソースのウェブフレームワークです。 Ruby on Railsは「設定より規約」の原則に従っており、効率的に作業を行うために再開発を行う必要をなくしてくれます。

AWS(Amazon Web Services)

Amazon Web Services (AWS)は、仮想空間を機軸とした、クラスター状のコンピュータ・ネットワーク・データベース・ストーレッジ・サポートツールをAWSというインフラから提供する商用サービスです。

Q&A

解決済

1回答

2772閲覧

productionモードでDeviseの確認メールが送信されてこない

begenner

総合スコア79

Devise

Deviseとは、Ruby-on-Railsの認証機能を追加するプラグインです。

Ruby on Rails 4

Ruby on Rails4はRubyによって書かれたオープンソースのウェブフレームワークです。 Ruby on Railsは「設定より規約」の原則に従っており、効率的に作業を行うために再開発を行う必要をなくしてくれます。

AWS(Amazon Web Services)

Amazon Web Services (AWS)は、仮想空間を機軸とした、クラスター状のコンピュータ・ネットワーク・データベース・ストーレッジ・サポートツールをAWSというインフラから提供する商用サービスです。

0グッド

0クリップ

投稿2019/10/24 10:15

現在AWS(amazon linux2)にRailsアプリをデプロイし、ブラウザでの動作確認をしていました。
developmentモードでは

  • 確認メールの送信(letter_opener_web を使用)
  • パスワードリセット時のメール認証

は動作を確認できましたが、AWS上(productionモード、メール送信にはGmailを使用)では登録したメールに確認・変更のためのメールが送信されてきません。

Ruby on Rails - rails4 devise 確認メールを送れない|teratail

を参考に設定を確認してみましたがわかりませんでした(m_ _m)

もしわかる方がいらっしゃればご教授いただきますようよろしくお願いいたします(m_ _m)

【前提条件】
下記の語句は置き換えてあります

  • Railsのアプリ名: 【webapp】
  • 取得済みのドメイン: 【myDomain】
  • Railsアプリ用のGmail: 【appGmail】
  • 自分のグローバルIP: 【my_global_ip】
  • 自分のメールアドレス:【myEmail】

動作環境

RailsAWS
Ruby: 2.4.5Amazon linux2
Rails: 4.2.11.1nginx: 1.16.1
Devise: 4.7.1EC2、RDS(MySQL)
dotenv-railsを使用HTTPS(Route53)設定済

期待する動作

productionモードでアカウント作成用の確認メールが入力したメールアドレスに送信されること

エラー内容

  • ブラウザ上ではエラーは発生していない(message A message with a confirmation link has been sent to your email address. Please follow the link to activate your account.が表示される)
  • 該当しそうなログ

bash

1# I, [2019-10-24T18:37:09.471732 #3473] INFO -- : Started POST "/users" for 【my_global_ip】 at 2019-10-24 # 18:37:09 +0900 2# I, [2019-10-24T18:37:09.473439 #3473] INFO -- : Processing by # Public::Settings::Users::RegistrationsController#create as HTML 3# I, [2019-10-24T18:37:09.473501 #3473] INFO -- : Parameters: {"utf8"=>"✓", # "authenticity_token"=>"MfhA0E7vAiJBw5gBdP/tmR4JNS6MMxET47auIKR98k/ilf/# lqVbGIDgUb9pRIMgDOBz3HQc/ybDyULvECDqv2g==", "user"=>{"email"=>"【myEmail】", # "password"=>"[FILTERED]", "password_confirmation"=>"[FILTERED]"}, "commit"=>"アカウント作成"} 4# D, [2019-10-24T18:37:09.640294 #3473] DEBUG -- : (0.7ms) BEGIN 5# D, [2019-10-24T18:37:09.643581 #3473] DEBUG -- : User Exists (0.7ms) SELECT 1 AS one FROM # `users` WHERE `users`.`email` = BINARY '【myEmail】' LIMIT 1 6# D, [2019-10-24T18:37:09.645892 #3473] DEBUG -- : SQL (0.6ms) INSERT INTO `users` (`email`, # `encrypted_password`, `created_at`, `updated_at`, `confirmation_token`, `confirmation_sent_at`) VALUES # ('【myEmail】', '$2a$11$IipWgiWvpH33/IAHrbBS2eqssRnT4B0cIYjigiS/a0mZf1.VerfBy', # '2019-10-24 18:37:09', '2019-10-24 18:37:09', '1yBpxGtz8xkboY2y-EPv', '2019-10-24 18:37:09') 7# D, [2019-10-24T18:37:09.648726 #3473] DEBUG -- : (2.2ms) COMMIT 8# I, [2019-10-24T18:37:10.187504 #3473] INFO -- : Rendered vendor/bundle/ruby/2.4.0/gems/devise-# i18n-1.8.2/app/views/devise/mailer/confirmation_instructions.html.erb (1.0ms) 9# D, [2019-10-24T18:37:10.438328 #3473] DEBUG -- : 10# Devise::Mailer#confirmation_instructions: processed outbound mail in 786.2ms 11# I, [2019-10-24T18:37:13.312854 #3473] INFO -- : 12# Sent mail to 【myEmail】 (2874.3ms) 13# D, [2019-10-24T18:37:13.312946 #3473] DEBUG -- : Date: Thu, 24 Oct 2019 18:37:10 +0900 14# From: 【appGmail】 15# Reply-To: 【appGmail】 16# To: 【myEmail】 17# Message-ID: <5db170c66c75b_d912ac364ba4f581921c@ip-10-0-1-127.ap-# northeast-1.compute.internal.mail> 18# Subject: Confirmation instructions 19# Mime-Version: 1.0 20# Content-Type: text/html; 21# charset=UTF-8 22# Content-Transfer-Encoding: 7bit 23# 24# <p>Welcome 【myEmail】!</p> 25# 26# <p>You can confirm your account email through the link below:</p> 27# 28# <p><a href="【myDomain】/users/confirmation?# confirmation_token=1yBpxGtz8xkboY2y-EPv">Confirm my account</a></p>

該当しそうなコード

参考にしたサイト: Ruby on Rails - rails4 devise 確認メールを送れない|teratail

  • (1 / 2) config/environments/production.rb

ruby

1Rails.application.configure do 2 config.cache_classes = true 3 config.eager_load = true 4 config.consider_all_requests_local = false 5 config.action_controller.perform_caching = true 6 7 8 # Disable serving static files from the `/public` folder by default since 9 # Apache or NGINX already handles this. 10 config.serve_static_files = ENV['RAILS_SERVE_STATIC_FILES'].present? 11 12 config.assets.js_compressor = :uglifier 13 # config.assets.css_compressor = :sass 14 config.assets.compile = false 15 config.assets.digest = true 16 # Ignore bad email addresses and do not raise email delivery errors. 17 # Set this to true and configure the email server for immediate delivery to raise delivery errors. 18 # 本番環境のURL指定 19 config.action_mailer.default_url_options = { host: '【myDomain】 ' } 20 config.action_mailer.raise_delivery_errors = true 21 22 config.action_mailer.delivery_method = :smtp 23 config.action_mailer.smtp_settings = { 24 address: 'smtp.gmail.com', 25 port: 587, 26 domain: 'gmail.com', 27 user_name: ENV['gmail_address'], 28 password: ENV['gmail_password'], # Gmailアカウントにログインしてから作成したアプリ用の固有パスワード 29 authentication: 'plain', 30 enable_starttls_auto: true 31 } 32 33 config.i18n.fallbacks = true 34 config.active_support.deprecation = :notify 35 config.log_formatter = ::Logger::Formatter.new 36 config.active_record.dump_schema_after_migration = false 37 # 静的なファイルをRailsから返す 38 config.serve_static_files = true 39end
  • (2 / 2) config/initializers/devise.rb(デフォルトのコメントアウト行は削除してあります)

ruby

1# config/initializers/devise.rb 2 3# frozen_string_literal: true 4 5Devise.setup do |config| 6 # 変更 7 # config.secret_key = ENV['rails_secret_key'] 8 config.secret_key = ENV['rails_secret_key'] if Rails.env == 'production' 9 config.mailer_sender = ENV['gmail_address'] 10 require 'devise/orm/active_record' 11 config.case_insensitive_keys = [:email] 12 config.strip_whitespace_keys = [:email] 13 config.skip_session_storage = [:http_auth] 14 config.stretches = Rails.env.test? ? 1 : 11 15 config.reconfirmable = true 16 config.expire_all_remember_me_on_sign_out = true 17 config.password_length = 8..128 18 config.email_regexp = /\A[^@\s]+@[^@\s]+\z/ 19 config.reset_password_within = 6.hours 20 config.scoped_views = true 21 config.sign_out_via = :get 22 # google, facebook認証用の追加行 23 config.omniauth :facebook, ENV['facebook_app_id'], ENV['facebook_app_secret'] 24 config.omniauth :google_oauth2, ENV['goole_omni_key'], ENV['google_omni_secret'], name: :google, scope: %w(email) 25end

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

guest

回答1

0

自己解決

すいません、設定の反映がかなり遅かったようです(なぜ遅かったかはわかりません)
現在は問題なく動作しています。

投稿2019/10/24 12:33

begenner

総合スコア79

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.48%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問