前提
ruby on rails でアプリを製作し、Herokuでリリースして本番環境で運用できるか確認しているところです。
ユーザー登録の際にDeviseを用いた認証を設定しているのですが、メールが送信されません。
SendGridへの登録、HerokuのAddonsにSendGridの追加、HerokuのConfig VarsにSENDGRID_APIKEY、SENDGRID_PASSWORD、SENDGRID_USERNAMEを設定しています。
Gmailの2段階認証も行っています。
実現したいこと
ここに実現したいことを箇条書きで書いてください。
- メールが届くようにする
発生している問題・エラーメッセージ
heroku logs -tを確認すると以下のエラーが出ていました。
stmpの設定が間違っているのではないかと考えているのですが、どこが間違っているのか良く分かりませんでした。
INFO -- : [42e2f8ce-1c3a-4b87-86bb-6fb25d57f2ec] Delivered mail INFO -- : [42e2f8ce-1c3a-4b87-86bb-6fb25d57f2ec] Completed 500 Internal Server Error in 44ms (ActiveRecord: 18.4ms | Allocations: 6214) FATAL -- : [42e2f8ce-1c3a-4b87-86bb-6fb25d57f2ec] ArgumentError (SMTP-AUTH requested but missing secret phrase):```
該当のソースコード
production.rbの設定
environments/production.rb
1 2require "active_support/core_ext/integer/time" 3 4Rails.application.configure do 5 6 config.cache_classes = true 7 8 config.eager_load = true 9 10 config.consider_all_requests_local = false 11 config.action_controller.perform_caching = true 12 13 config.public_file_server.enabled = ENV['RAILS_SERVE_STATIC_FILES'].present? 14 15 config.assets.compile = true 16 17 config.active_storage.service = :local 18 19 config.log_tags = [ :request_id ] 20 21/////////////////////////////////////////////ここからMailerの設定 22 config.action_mailer.perform_caching = false 23 #default url 24 config.action_mailer.default_url_options = {host: "○○○.herokuapp.com"} 25 #mail setting 26 config.action_mailer.raise_delivery_errors = true 27 config.action_mailer.delivery_method = :smtp 28 ActionMailer::Base.smtp_settings = { 29 :user_name => 'apikey', 30 :password => ENV['SENDGRID_API_KEY'], 31 :domain => '○○○.herokuapp.com', 32 :address => 'smtp.sendgrid.net', 33 :port => 587, 34 :authentication => :plain, 35 :enable_starttls_auto => true 36 } 37//////////////////////////////////////////////////////////////////////////////////////////////// 38 39config.i18n.fallbacks = true 40 41 config.active_support.deprecation = :notify 42 43 config.active_support.disallowed_deprecation = :log 44 45 config.active_support.disallowed_deprecation_warnings = [] 46 47 config.log_formatter = ::Logger::Formatter.new 48 49 if ENV["RAILS_LOG_TO_STDOUT"].present? 50 logger = ActiveSupport::Logger.new(STDOUT) 51 logger.formatter = config.log_formatter 52 config.logger = ActiveSupport::TaggedLogging.new(logger) 53 end 54 55 config.active_record.dump_schema_after_migration = false
application_mailer.rbの設定
application_mailer.rb
1 2class ApplicationMailer < ActionMailer::Base 3 default from: "△△△@gmail.com" 4 layout 'mailer' 5end
HerokuのConfig Varsには以下を追加しました
- SENDGRID_APIKEY
- SENDGRID_PASSWORD
- SENDGRID_USERNAME
足りていない情報があればコメントいただけますと幸いです。
よろしくお願いします。
参考
Ruby on Railsでメール送信
Rails6 アプリからメールを送信する デプロイ環境編 - Qiita
Heroku にデプロイした Rails アプリから SENDGRID を使ってメール送信する
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。