前提・実現したいこと
現在「現場で使えるRuby on Rails5」を使ってRailsを勉強しており、Todoアプリの中でmailcatcherでテストメールを送れるようになりたいです。
発生している問題・エラーメッセージ
エラー等は発生してないのですが、なぜかテストメールが送られてこないです。
mailcatcherを使用しております。
Todoリスト登録が完了したら、タスク登録の完了メールを送るようにしていますが、メールが送られてきません。
コード等も間違ってないと思います。
原因が分かる方がおりましたら、ご教示いただけないでしょうか。
よろしくお願いいたします。
該当のソースコード
development.rb
Rails
1require "active_support/core_ext/integer/time" 2 3Rails.application.configure do 4 # Settings specified here will take precedence over those in config/application.rb. 5 6 # In the development environment your application's code is reloaded any time 7 # it changes. This slows down response time but is perfect for development 8 # since you don't have to restart the web server when you make code changes. 9 config.cache_classes = false 10 11 # Do not eager load code on boot. 12 config.eager_load = false 13 14 # Show full error reports. 15 config.consider_all_requests_local = true 16 17 # Enable/disable caching. By default caching is disabled. 18 # Run rails dev:cache to toggle caching. 19 if Rails.root.join('tmp', 'caching-dev.txt').exist? 20 config.action_controller.perform_caching = true 21 config.action_controller.enable_fragment_cache_logging = true 22 23 config.cache_store = :memory_store 24 config.public_file_server.headers = { 25 'Cache-Control' => "public, max-age=#{2.days.to_i}" 26 } 27 else 28 config.action_controller.perform_caching = false 29 30 config.cache_store = :null_store 31 end 32 33 # Store uploaded files on the local file system (see config/storage.yml for options). 34 config.active_storage.service = :local 35 36 # Don't care if the mailer can't send. 37 config.action_mailer.raise_delivery_errors = false 38 config.action_mailer.delivery_method = :smtp 39 config.action_mailer.smtp_settings = {address: '127.0.0.1',port: 1025} 40 41 config.action_mailer.perform_caching = false 42 43 # Print deprecation notices to the Rails logger. 44 config.active_support.deprecation = :log 45 46 # Raise exceptions for disallowed deprecations. 47 config.active_support.disallowed_deprecation = :raise 48 49 # Tell Active Support which deprecation messages to disallow. 50 config.active_support.disallowed_deprecation_warnings = [] 51 52 # Raise an error on page load if there are pending migrations. 53 config.active_record.migration_error = :page_load 54 55 # Highlight code that triggered database queries in logs. 56 config.active_record.verbose_query_logs = true 57 58 # Debug mode disables concatenation and preprocessing of assets. 59 # This option may cause significant delays in view rendering with a large 60 # number of complex assets. 61 config.assets.debug = true 62 63 # Suppress logger output for asset requests. 64 config.assets.quiet = true 65 66 # Raises error for missing translations. 67 # config.i18n.raise_on_missing_translations = true 68 69 # Annotate rendered view with file names. 70 # config.action_view.annotate_rendered_view_with_filenames = true 71 72 # Use an evented file watcher to asynchronously detect changes in source code, 73 # routes, locales, etc. This feature depends on the listen gem. 74 # config.file_watcher = ActiveSupport::EventedFileUpdateChecker 75 76 # Uncomment if you wish to allow Action Cable access from any origin. 77 # config.action_cable.disable_request_forgery_protection = true 78end 79
application_mailer.rb
Rails
1class ApplicationMailer < ActionMailer::Base 2 default from: "example@railstutorial.com" 3 layout "mailer" 4end
task_mailer.rb
Rails
1class TaskMailer < ApplicationMailer 2 def creation_email(task) 3 @task = task 4 mail( 5 subject: 'タスク作成完了', 6 to: 'user@example.com', 7 from: 'example@railstutorial.com' 8 ) 9 end 10end
tasks_controller.rb
Rails
1class TasksController < ApplicationController 2 before_action :set_task, only: [:show, :edit, :update, :destroy] 3 4 def index 5 @q = current_user.tasks.ransack(params[:q]) 6 @tasks = @q.result(distinct: true) 7 end 8 9 def show 10 end 11 12 def new 13 @task = Task.new 14 end 15 16 def edit 17 end 18 19 def create 20 @task = current_user.tasks.new(task_params) 21 22 if params[:back].present? 23 render :new 24 return 25 end 26 27 if @task.save 28 TaskMailer.creation_email(@task).deliver_now 29 redirect_to tasks_url, notice: "タスク「#{@task.name}」を登録しました。" 30 else 31 render "new" 32 end 33 end 34 35 def update 36 @task.update!(task_params) 37 redirect_to task_url, notice: "タスク「#{@task.name}」を更新しました。" 38 end 39 40 def destroy 41 @task.destroy 42 redirect_to tasks_url, notice: "タスク「#{@task.name} 」を削除しました。" 43 end 44 45 def confirm_new 46 @task = current_user.tasks.new(task_params) 47 render :new unless @task.valid? 48 end 49 50 private 51 52 def task_params 53 params.require(:task).permit(:name, :description) 54 end 55 56 def set_task 57 @task = current_user.tasks.find(params[:id]) 58 end 59end
creation_email.html.slim
Rails
1| 以下のタスクを作成しました 2 3ul 4 li 5 | 名称: 6 = @task.name 7 li 8 | 詳しい説明 9 = simple_format(@task.description)
creation_email.text.slim
Rails
1| 以下のタスクを作成しました 2= "\n" 3| 名称: 4= @task.name 5= "\n" 6| 詳しい説明: 7= "\n" 8= @task.description
####ログ
Terminal
1Started POST "/tasks" for 127.0.0.1 at 2021-09-16 20:57:12 +0900 2Processing by TasksController#create as HTML 3 Parameters: {"authenticity_token"=>"[FILTERED]", "task"=>{"name"=>"一覧表示機能の実装", "description"=>"一覧アクションと一覧画面を実装する"}, "commit"=>"登録"} 4 User Load (0.6ms) SELECT "users".* FROM "users" WHERE "users"."id" = ? LIMIT ? [["id", 3], ["LIMIT", 1]] 5 ↳ app/controllers/application_controller.rb:8:in `current_user' 6 TRANSACTION (0.1ms) begin transaction 7 ↳ app/controllers/tasks_controller.rb:27:in `create' 8 Task Create (7.9ms) INSERT INTO "tasks" ("name", "description", "created_at", "updated_at", "user_id") VALUES (?, ?, ?, ?, ?) [["name", "一覧表示機能の実装"], ["description", "一覧アクションと一覧画面を実装する"], ["created_at", "2021-09-16 11:57:12.167880"], ["updated_at", "2021-09-16 11:57:12.167880"], ["user_id", 3]] 9 ↳ app/controllers/tasks_controller.rb:27:in `create' 10 TRANSACTION (6.2ms) commit transaction 11 ↳ app/controllers/tasks_controller.rb:27:in `create' 12 Rendering layout layouts/mailer.html.slim 13 Rendering task_mailer/creation_email.html.slim within layouts/mailer 14 Rendered task_mailer/creation_email.html.slim within layouts/mailer (Duration: 0.8ms | Allocations: 280) 15 Rendered layout layouts/mailer.html.slim (Duration: 2.4ms | Allocations: 365) 16 Rendering layout layouts/mailer.text.slim 17 Rendering task_mailer/creation_email.text.slim within layouts/mailer 18 Rendered task_mailer/creation_email.text.slim within layouts/mailer (Duration: 0.3ms | Allocations: 52) 19 Rendered layout layouts/mailer.text.slim (Duration: 2.2ms | Allocations: 128) 20TaskMailer#creation_email: processed outbound mail in 14.5ms 21Delivered mail 6143311836452_4fdc3958476d7@LAPTOP-O8JJ5S4B.mail (4132.4ms) 22Date: Thu, 16 Sep 2021 20:57:12 +0900 23From: example@railstutorial.com 24To: user@example.com 25Message-ID: <6143311836452_4fdc3958476d7@LAPTOP-O8JJ5S4B.mail> 26Subject: =?UTF-8?Q?=E3=82=BF=E3=82=B9=E3=82=AF=E4=BD=9C=E6=88=90=E5=AE=8C=E4=BA=86?= 27Mime-Version: 1.0 28Content-Type: multipart/alternative; 29 boundary="--==_mimepart_614331183515c_4fdc39584755f"; 30 charset=UTF-8 31Content-Transfer-Encoding: 7bit 32 33 34----==_mimepart_614331183515c_4fdc39584755f 35Content-Type: text/plain; 36 charset=UTF-8 37Content-Transfer-Encoding: base64 38 395Lul5LiL44Gu44K/44K544Kv44KS5L2c5oiQ44GX44G+44GX44GfDQrlkI3n 40p7A65LiA6Kan6KGo56S65qmf6IO944Gu5a6f6KOFDQroqbPjgZfjgYToqqzm 41mI46DQrkuIDopqfjgqLjgq/jgrfjg6fjg7PjgajkuIDopqfnlLvpnaLjgpLl 42rp/oo4XjgZnjgos= 43 44----==_mimepart_614331183515c_4fdc39584755f 45Content-Type: text/html; 46 charset=UTF-8 47Content-Transfer-Encoding: base64 48 49PGh0bWw+PGJvZHk+5Lul5LiL44Gu44K/44K544Kv44KS5L2c5oiQ44GX44G+ 5044GX44GfPHVsPjxsaT7lkI3np7A65LiA6Kan6KGo56S65qmf6IO944Gu5a6f 516KOFPC9saT48bGk+6Kmz44GX44GE6Kqs5piOPHA+5LiA6Kan44Ki44Kv44K3 5244On44Oz44Go5LiA6Kan55S76Z2i44KS5a6f6KOF44GZ44KLPC9wPjwvbGk+ 53PC91bD48L2JvZHk+PC9odG1sPg== 54 55----==_mimepart_614331183515c_4fdc39584755f--
試したこと
エラー等も起きてないため、何をしていいか分からずで
mailcatcherを再起動したぐらいになります。
補足情報(FW/ツールのバージョンなど)
Windows 10
Ruby 3.0.2
Rails 6.1.4.1
yarn 1.22.10
あなたの回答
tips
プレビュー