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

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

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

SendGridは、米SendGrid社のクラウド型メール配信サービス。アカウントを作成するだけですぐに利用することが可能です。さらに到達率向上のための送信ドメイン認証対応や、柔軟性のあるスケーラビリティなど多くの機能を有します。

Ruby on Rails 5

Ruby on Rails 5は、オープンソースのWebアプリケーションフレームワークです。「同じことを繰り返さない」というRailsの基本理念のもと、他のフレームワークより少ないコードで簡単に開発できるよう設計されています。

Heroku

HerokuはHeroku社が開発と運営を行っているPaaSの名称です。RubyやNode.js、Python、そしてJVMベース(Java、Scala、Clojureなど)の複数のプログラミング言語をサポートしている。

Ruby on Rails

Ruby on Railsは、オープンソースのWebアプリケーションフレームワークです。「同じことを繰り返さない」というRailsの基本理念のもと、他のフレームワークより少ないコードで簡単に開発できるよう設計されています。

Docker

Dockerは、Docker社が開発したオープンソースのコンテナー管理ソフトウェアの1つです

Q&A

0回答

334閲覧

本番環境で送られるメールのurlがlocalhostで送られてくる。

SNGin

総合スコア16

SendGrid

SendGridは、米SendGrid社のクラウド型メール配信サービス。アカウントを作成するだけですぐに利用することが可能です。さらに到達率向上のための送信ドメイン認証対応や、柔軟性のあるスケーラビリティなど多くの機能を有します。

Ruby on Rails 5

Ruby on Rails 5は、オープンソースのWebアプリケーションフレームワークです。「同じことを繰り返さない」というRailsの基本理念のもと、他のフレームワークより少ないコードで簡単に開発できるよう設計されています。

Heroku

HerokuはHeroku社が開発と運営を行っているPaaSの名称です。RubyやNode.js、Python、そしてJVMベース(Java、Scala、Clojureなど)の複数のプログラミング言語をサポートしている。

Ruby on Rails

Ruby on Railsは、オープンソースのWebアプリケーションフレームワークです。「同じことを繰り返さない」というRailsの基本理念のもと、他のフレームワークより少ないコードで簡単に開発できるよう設計されています。

Docker

Dockerは、Docker社が開発したオープンソースのコンテナー管理ソフトウェアの1つです

0グッド

0クリップ

投稿2019/11/28 13:10

編集2019/11/28 14:01

railsチュートリアルをやっているのですが、11章でメールを送るところで、herokuのsendgridでメールを送ったのですが
、メールが届かず、logをみるとlocalhostで送られてしまいます。

ユーザーがsign upした時に送られるメールです。

docker-compose.yml version: '3' services: db: image: postgres:11 volumes: - ./tmp/db:/var/lib/postgresql/data environment: POSTGRES_USER: postgres POSTGRES_PASSWORD: postgres ports: - '5433:5432' web: stdin_open: true tty: true build: . command: bash -c "rm -f tmp/pids/server.pid && bundle exec rails s -p 3000 -b '0.0.0.0'" volumes: - .:/myapp ports: - "3000:3000" depends_on: - db
Dockerfile FROM ruby:2.5 ENV RUBYOPT -EUTF-8 RUN apt-get update -qq && apt-get install -y nodejs postgresql-client imagemagick vim RUN mkdir /myapp WORKDIR /myapp COPY Gemfile /myapp/Gemfile COPY Gemfile.lock /myapp/Gemfile.lock RUN bundle install COPY . /myapp # Add a script to be executed every time the container starts. #COPY entrypoint.sh /usr/bin/ #RUN chmod +x /usr/bin/entrypoint.sh #ENTRYPOINT ["entrypoint.sh"] #EXPOSE 3000 # Start the main process. CMD ["rails", "server", "-b", "0.0.0.0"]
config/environment/production.rb Rails.application.configure do # Settings specified here will take precedence over those in config/application.rb. # Code is not reloaded between requests. config.cache_classes = true # Eager load code on boot. This eager loads most of Rails and # your application in memory, allowing both threaded web servers # and those relying on copy on write to perform better. # Rake tasks automatically ignore this option for performance. config.eager_load = true # Full error reports are disabled and caching is turned on. config.consider_all_requests_local = false config.action_controller.perform_caching = true # Ensures that a master key has been made available in either ENV["RAILS_MASTER_KEY"] # or in config/master.key. This key is used to decrypt credentials (and other encrypted files). # config.require_master_key = true # Disable serving static files from the `/public` folder by default since # Apache or NGINX already handles this. config.public_file_server.enabled = ENV['RAILS_SERVE_STATIC_FILES'].present? # Compress JavaScripts and CSS. config.assets.js_compressor = :uglifier # config.assets.css_compressor = :sass # Do not fallback to assets pipeline if a precompiled asset is missed. config.assets.compile = false # `config.assets.precompile` and `config.assets.version` have moved to config/initializers/assets.rb # Enable serving of images, stylesheets, and JavaScripts from an asset server. # config.action_controller.asset_host = 'http://assets.example.com' # Specifies the header that your server uses for sending files. # config.action_dispatch.x_sendfile_header = 'X-Sendfile' # for Apache # config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect' # for NGINX # Store uploaded files on the local file system (see config/storage.yml for options) config.active_storage.service = :local # Mount Action Cable outside main process or domain # config.action_cable.mount_path = nil # config.action_cable.url = 'wss://example.com/cable' # config.action_cable.allowed_request_origins = [ 'http://example.com', /http://example.*/ ] # Force all access to the app over SSL, use Strict-Transport-Security, and use secure cookies. config.force_ssl = true # Use the lowest log level to ensure availability of diagnostic information # when problems arise. config.log_level = :debug # Prepend all log lines with the following tags. config.log_tags = [ :request_id ] # Use a different cache store in production. # config.cache_store = :mem_cache_store # Use a real queuing backend for Active Job (and separate queues per environment) # config.active_job.queue_adapter = :resque # config.active_job.queue_name_prefix = "myapp_#{Rails.env}" config.action_mailer.perform_caching = false # Ignore bad email addresses and do not raise email delivery errors. # Set this to true and configure the email server for immediate delivery to raise delivery errors. config.action_mailer.raise_delivery_errors = true config.action_mailer.delivery_method = :smtp config.action_mailer.default_url_options = { host: 'samapp.herokuapp.com' } 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 } # Enable locale fallbacks for I18n (makes lookups for any locale fall back to # the I18n.default_locale when a translation cannot be found). config.i18n.fallbacks = true # Send deprecation notices to registered listeners. config.active_support.deprecation = :notify # Use default logging formatter so that PID and timestamp are not suppressed. config.log_formatter = ::Logger::Formatter.new # Use a different logger for distributed setups. # require 'syslog/logger' # config.logger = ActiveSupport::TaggedLogging.new(Syslog::Logger.new 'app-name') if ENV["RAILS_LOG_TO_STDOUT"].present? logger = ActiveSupport::Logger.new(STDOUT) logger.formatter = config.log_formatter config.logger = ActiveSupport::TaggedLogging.new(logger) end # Do not dump schema after migrations. config.active_record.dump_schema_after_migration = false end
mailer/application_mailer.rb class ApplicationMailer < ActionMailer::Base default from: 'noreply@example.com' layout 'mailer' end
app/views/user_mailer/account_activation.html.erb <h1>Sample App</h1> <p>Hi <%= @user.name %>,</p> <p> Welcome to the Sample App!Click on the link below to activate your account: </p> <%= link_to "Activate", edit_account_activation_url(@user.activation_token, email: @user.email) %>

ログは下記です。

heroku[router]: at=info method=POST path="/users" host=samapp.herokuapp.com request_id=fef14af2-0c23-4277-a855-a51dcf50da7e fwd="182.158.68.74" dyno=web.1 connect=1ms service=734ms status=302 bytes=973 protocol=https app[web.1]: UserMailer#account_activation: processed outbound mail in 278.7ms app[web.1]: Sent mail to samsam@yahoo.co.jp (10.4ms) app[web.1]: Date: Thu, 28 Nov 2019 13:27:14 +0000 app[web.1]: From: noreply@example.com app[web.1]: To: samsam@yahoo.co.jp app[web.1]: Message-ID: <5ddfcb3210d2b_112b1f799df670767d2@c00df1e4-6952-489d-801d-4e7a6566e042.mail> app[web.1]: Subject: Account activation app[web.1]: Mime-Version: 1.0 app[web.1]: Content-Type: multipart/alternative; app[web.1]: boundary="--==_mimepart_5ddfcb32ec90_112b1f799df67076617"; app[web.1]: charset=UTF-8 app[web.1]: Content-Transfer-Encoding: 7bit app[web.1]: ----==_mimepart_5ddfcb32ec90_112b1f799df67076617 app[web.1]: Content-Type: text/plain; app[web.1]: charset=UTF-8 app[web.1]: Content-Transfer-Encoding: 7bit app[web.1]: Hi Gin, app[web.1]: app[web.1]: Welcome to the Sample App! Click on the link below to activate your account: app[web.1]: app[web.1]: http://localhost:3000/account_activations/f3LX0NuKquvU1qFDhkqjhg/edit?email=samsam%40yahoo.co.jp app[web.1]: app[web.1]: app[web.1]: ----==_mimepart_5ddfcb32ec90_112b1f799df67076617 app[web.1]: Content-Type: text/html; app[web.1]: charset=UTF-8 app[web.1]: Content-Transfer-Encoding: 7bit app[web.1]: app[web.1]: <!DOCTYPE html> app[web.1]: <html> app[web.1]: <head> app[web.1]: <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> app[web.1]: <style> app[web.1]: /* Email styles need to be inline */ app[web.1]: </style> app[web.1]: </head> app[web.1]: app[web.1]: <body> app[web.1]: <h1>Sample App</h1> app[web.1]: app[web.1]: <p>Hi Gin,</p> app[web.1]: app[web.1]: <p> app[web.1]: Welcome to the Sample App!Click on the link below to activate your account: app[web.1]: </p> app[web.1]: app[web.1]: <a href="http://localhost:3000/account_activations/f3LX0NuKquvU1qFDhkqjhg/edit?email=samsam%40yahoo.co.jp">Activate</a> app[web.1]: app[web.1]: </body> app[web.1]: </html> app[web.1]: app[web.1]: ----==_mimepart_5ddfcb32ec90_112b1f799df67076617--

現状はこのような感じです。

ご教授頂けると嬉しいです。
よろしくお願いします。

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

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

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

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

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

otn

2019/11/28 13:24

> メールが届かず、logをみるとlocalhostで送られてしまいます。 ログが書いてませんが??
SNGin

2019/11/28 13:36

申し訳ありません。 追記しました。 10000文字超えてしまうため、多少省略してます。
otn

2019/11/28 13:38

> logをみるとlocalhostで送られてしまいます。 の文章の意味が分かりません。ログのどこのことですか?それをどう解釈したのですか?
SNGin

2019/11/28 13:39

`http://localhost:3000/account_activations/f3LX0NuKquvU1qFDhkqjhg/edit?email=samsam%40yahoo.co.jp`の部分です。 リンクがlocalhostになっているところです。
SNGin

2019/11/28 13:41

期待しているのはactivationのリンクがhttps://samapp.herokuapp.com/account_activations/f3LX0NuKquvU1qFDhkqjhg/edit?email=samsam%40yahoo.co.jpで送られてきて欲しいのです。
otn

2019/11/28 13:45

メールは届いたが、メールの内容が期待通りでないということですか?
SNGin

2019/11/28 13:47

メールの<%= link_to "Activate", edit_account_activation_url(@user.activation_token,email: @user.email) %>で生成されるリンクがproduction環境のhostで送られて欲しいというのが主題です。 メールも送られてきませんが、、、
otn

2019/11/28 14:12

ああ、解決すべき問題が2つがあるということですね。 > 送られてしまいます。 > 届かず、 メールが送られたにもかかわらず、届かないのかと思ってしまいました。メール配送の話ではないのなら、他の方の回答をお待ちください。
winterboum

2019/11/28 14:46

ざっと見ではよさ気なのですが、はて、です サーバはproduction環境で立ち上げていますね?
SNGin

2019/11/28 14:54

Herokuにデプロイしているのでproduction環境で立ち上がっていると思われるのですが、dockerでデプロイした時に何かおかしかったのでしょうか?
winterboum

2019/11/28 14:58

Herokuは経験がないので、、そこはわかりません。
SNGin

2019/11/28 15:04

railsの設定がおかしくないのであれば、herokuへのデプロイに問題があるかもしれないので格闘してみます。
take88

2019/11/30 05:47

productionで動いてなさそうに見えますね。heroku に 環境変数は設定してますか?
SNGin

2019/11/30 12:21

heroku config:get SENDGRID_USERNAME 上記のコマンドを打つとちゃんと設定されているようなのですが、、、。 他に設定しないといけないものはあるのでしょうか?
take88

2019/11/30 12:27

heroku config:set ENV_NAME="production" が必要な気がしますね。
SNGin

2019/11/30 12:33

上記の環境変数をセットしてrailsもしくはdocker側で何か設定が必要ですか?
guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

まだ回答がついていません

会員登録して回答してみよう

アカウントをお持ちの方は

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

ただいまの回答率
85.48%

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

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

質問する

関連した質問