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--
現状はこのような感じです。
ご教授頂けると嬉しいです。
よろしくお願いします。
あなたの回答
tips
プレビュー