前提・実現したいこと
お問い合わせのメッセージを送った際に、お問い合わせをした人に対して、メールを送れる様にしたいのですが、
Errno::ECONNREFUSED (Connection refused - connect(2) for "localhost" port 25):
とエラーになってしまい、初めてAction Mailer機能を触るので、どこをどう修正すればいいのかわかりません。どなたかわかる方がいらっしゃれば助けて下さい。
発生している問題・エラーメッセージ
"ターミナル上" Rendering contact_message_mailer/contact_message.html.erb within layouts/mailer Rendered contact_message_mailer/contact_message.html.erb within layouts/mailer (Duration: 0.1ms | Allocations: 6) Rendering contact_message_mailer/contact_message.text.erb within layouts/mailer Rendered contact_message_mailer/contact_message.text.erb within layouts/mailer (Duration: 0.0ms | Allocations: 4) ContactMessageMailer#contact_message: processed outbound mail in 4.2ms Delivered mail 5f5f3c64d89ea_1ded5c6c1033d9@Taikis-MacBook-Air.local.mail (3.2ms) Date: Mon, 14 Sep 2020 18:48:20 +0900 From: sample@icloud.com To: contact@icloud.com Message-ID: <5f5f3c64d89ea_1ded5c6c1033d9@Taikis-MacBook-Air.local.mail> Subject: =?UTF-8?Q?=E3=81=8A=E5=95=8F=E3=81=84=E5=90=88=E3=82=8F=E3=81=9B=E5=86=85=E5=AE=B9=E3=81=AE=E7=A2=BA=E8=AA=8D?= Mime-Version: 1.0 Content-Type: multipart/alternative; boundary="--==_mimepart_5f5f3c64d7fa5_1ded5c6c10321d"; charset=UTF-8 Content-Transfer-Encoding: 7bit ----==_mimepart_5f5f3c64d7fa5_1ded5c6c10321d Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: base64 SG9uZGHjgZXjgpPjgIHjgYrllY/jgYTlkIjjgo/jgZvjgYLjgorjgYzjgajj gYbjgZTjgZbjgYTjgb7jgZnjgIINCg0K5Lul5LiL44Gu5YaF5a6544Gr44Gm 44CB44GK5ZWP44GE5ZCI44KP44Gb44KS5om/44KK44G+44GX44Gf44CCDQrj g6Hjg7zjg6vlsYrjgYTjgabjgYTjgb7jgZnjgYvvvJ8NCg0K ----==_mimepart_5f5f3c64d7fa5_1ded5c6c10321d Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: base64 PCFET0NUWVBFIGh0bWw+DQo8aHRtbD4NCiAgPGhlYWQ+DQogICAgPG1ldGEg aHR0cC1lcXVpdj0iQ29udGVudC1UeXBlIiBjb250ZW50PSJ0ZXh0L2h0bWw7 IGNoYXJzZXQ9dXRmLTgiIC8+DQogICAgPHN0eWxlPg0KICAgICAgLyogRW1h aWwgc3R5bGVzIG5lZWQgdG8gYmUgaW5saW5lICovDQogICAgPC9zdHlsZT4N CiAgPC9oZWFkPg0KDQogIDxib2R5Pg0KICAgIDxoMj5Ib25kYeOBleOCk+OA geOBiuWVj+OBhOWQiOOCj+OBm+OBguOCiuOBjOOBqOOBhuOBlOOBluOBhOOB vuOBmeOAgjwvaDI+DQo8cD7ku6XkuIvjga7lhoXlrrnjgavjgabjgIHjgYrl lY/jgYTlkIjjgo/jgZvjgpLmib/jgorjgb7jgZfjgZ/jgII8YnI+44Oh44O8 44Or5bGK44GE44Gm44GE44G+44GZ44GL77yfPC9wPg0KDQogIDwvYm9keT4N CjwvaHRtbD4NCg== ----==_mimepart_5f5f3c64d7fa5_1ded5c6c10321d-- Completed 500 Internal Server Error in 40ms (ActiveRecord: 3.5ms | Allocations: 20072) Errno::ECONNREFUSED (Connection refused - connect(2) for "localhost" port 25): app/controllers/contacts_controller.rb:17:in `create'
該当のソースコード
"config/environments/development.rb" Rails.application.configure do config.cache_classes = false config.eager_load = false config.consider_all_requests_local = true if Rails.root.join('tmp', 'caching-dev.txt').exist? config.action_controller.perform_caching = true config.action_controller.enable_fragment_cache_logging = true config.cache_store = :memory_store config.public_file_server.headers = { 'Cache-Control' => "public, max-age=#{2.days.to_i}" } else config.action_controller.perform_caching = false config.cache_store = :null_store end config.active_storage.service = :local config.action_mailer.raise_delivery_errors = true config.action_mailer.perform_deliveries = true config.action_mailer.delivery_method = :smtp config.action_mailer.smtp_settings = { address: 'smtp.gmail.com', port: 587, domain: 'gmail.com', user_name: '<sample@gmail.com>', password: '<mlmt >', authentication: 'plain', enable_starttls_auto: true } config.action_mailer.default_url_options = { host: 'localhost:3000' } config.action_mailer.perform_caching = false config.active_support.deprecation = :log config.active_record.migration_error = :page_load config.active_record.verbose_query_logs = true config.assets.debug = true config.assets.quiet = true config.file_watcher = ActiveSupport::EventedFileUpdateChecker end "config/environments/production.rb" Rails.application.configure do config.cache_classes = true config.eager_load = true config.consider_all_requests_local = false config.action_controller.perform_caching = true config.public_file_server.enabled = ENV['RAILS_SERVE_STATIC_FILES'].present? config.assets.compile = false config.active_storage.service = :local config.log_level = :debug config.log_tags = [ :request_id ] config.action_mailer.perform_caching = false config.i18n.fallbacks = true config.active_support.deprecation = :notify config.log_formatter = ::Logger::Formatter.new if ENV["RAILS_LOG_TO_STDOUT"].present? logger = ActiveSupport::Logger.new(STDOUT) logger.formatter = config.log_formatter config.logger = ActiveSupport::TaggedLogging.new(logger) end config.active_record.dump_schema_after_migration = false config.action_mailer.raise_delivery_errors = true #メール送信ができなかった場合、エラーを発生させる config.action_mailer.perform_deliveries = true #メール送信を有効にする config.action_mailer.delivery_method = :smtp #メール送信する際に通信プロトコルSMTPを利用する ??? config.action_mailer.smtp_settings = { address: 'smtp.gmail.com', port: 587, domain: 'gmail.com', user_name: '<zvldvuofqt@gmail.com>', password: '<mlmtkhsumazjarji>', authentication: 'plain', enable_starttls_auto: true } config.action_mailer.default_url_options = { host: 'localhost:3000' } end "お問い合わせの controller" def create @contact = Contact.new( name: params[:name], email: params[:email], message: params[:message] ) if @contact.save ContactMessageMailer.contact_message(@contact).deliver_now redirect_to("/posts/index") else @name = params[:name] @email = params[:email] @message = params[:message] render("contacts/new") end end "Mailerのmethod" class ContactMessageMailer < ApplicationMailer def contact_message(contact) @name = contact.name @message = contact.message mail(to: contact.email, subject: 'お問い合わせ内容の確認') end end
試したこと
同じ様なエラーが出ていた方を参考にして "config/environments/production.rb"にも、Action Mailerのsmtp設定をしたのですがうまくいきません。
補足情報(FW/ツールのバージョンなど)
Rails 6.0.3.3
見づらくてすみません。もし他に必要な情報があれば、ぜひおっしゃって下さい。
そもそもproductionの話ということでよいのでしょうか?