前提・実現したいこと
Railsチュートリアルの11章でSendGridからメールが送られてこないエラーが発生しました。
Cloud 9では新しくユーザー登録後、Please check your email to activate your account
と画面上にきちんと表示されるのですが、Herokuの本番環境だとWe're sorry, but something went wrong.
と出てしまい困ってます。
どなたか助言いただけないでしょうか?丸二日このエラーと格闘しており、
いろいろググって試してみましたが、解決法がわかりません。
発生している問題・エラーメッセージ
$ heroku logs
2018-08-27T00:47:30.841589+00:00 app[web.1]: I, [2018-08-27T00:47:30.841521 #6] INFO -- : [a6255093-4c52-4e32-9cd6-8a4216580976] Completed 500 Internal Server Error in 702ms (ActiveRecord: 11.7ms) 2018-08-27T00:47:30.842539+00:00 app[web.1]: F, [2018-08-27T00:47:30.842467 #6] FATAL -- : [a6255093-4c52-4e32-9cd6-8a4216580976] 2018-08-27T00:47:30.842630+00:00 app[web.1]: F, [2018-08-27T00:47:30.842569 #6] FATAL -- : [a6255093-4c52-4e32-9cd6-8a4216580976] Net::SMTPFatalError (550 Unauthenticated senders not allowed 2018-08-27T00:47:30.842632+00:00 app[web.1]: ): 2018-08-27T00:47:30.842744+00:00 app[web.1]: F, [2018-08-27T00:47:30.842663 #6] FATAL -- : [a6255093-4c52-4e32-9cd6-8a4216580976] 2018-08-27T00:47:30.842840+00:00 app[web.1]: F, [2018-08-27T00:47:30.842782 #6] FATAL -- : [a6255093-4c52-4e32-9cd6-8a4216580976] app/models/user.rb:48:in `send_activation_email' 2018-08-27T00:47:30.842842+00:00 app[web.1]: [a6255093-4c52-4e32-9cd6-8a4216580976] app/controllers/users_controller.rb:22:in `create'
該当のソースコード
production.rb
(中略) config.active_record.dump_schema_after_migration = false config.action_mailer.raise_delivery_errors = true config.action_mailer.delivery_method = :smtp host = 'https://アプリ名.herokuapp.com' config.action_mailer.default_url_options = { host: host } ActionMailer::Base.smtp_settings = { :address => 'smtp.sendgrid.net', :port => '587', :authentication => :plain, :user_name => ENV['ユーザー名@heroku.com'], :password => ENV['パスワード'], :domain => 'heroku.com', :enable_starttls_auto => true } end
app/models/user.rb
(中略) #永続セッションのためにユーザーをデータベースに記憶する def remember self.remember_token = User.new_token update_attribute(:remember_digest, User.digest(remember_token)) end def forget update_attribute(:remember_digest, nil) end #トークンがダイジェストと一致したらtrueを返す def authenticated?(attribute, token) digest = send("#{attribute}_digest") return false if digest.nil? BCrypt::Password.new(digest).is_password?(token) end #アカウントを有効にする def activate update_columns(activated: true, activated_at: Time.zone.now) end #有効化のメールを送信する def send_activation_email UserMailer.account_activation(self).deliver_now end private #有効化トークンとダイジェストを作成及び代入する def create_activation_digest self.activation_token = User.new_token self.activation_digest = User.digest(activation_token) end
users_controller.rb
def create @user = User.new(user_params) if @user.save @user.send_activation_email flash[:info] = "Please check your email to activate your account" redirect_to root_url else render 'new' end end
試したこと
1、Herokuにクレジットカード情報を登録
2、
$ heroku config:get SENDGRID_USERNAME
$ heroku config:get SENDGRID_PASSWORD
これでユーザー名とパスワードは表示されたものを入力してます。
3、
$ heroku config:add SENDGRID_PASSWORD=パスワード --app アプリ名
$ heroku config:add SENDGRID_USERNAME=ユーザ名@heroku.com --app アプリ名
これも試しました
4、再起動
補足情報(FW/ツールのバージョンなど)
Rails5.1.4
AWS Cloud 9
回答1件
あなたの回答
tips
プレビュー