skip to Main Content

I’m in the development environment. When triggering an email in the UI, I get the error in the browser:

No template for interactive request
Admins::AdminsController#testmail is missing a template for request formats: text/html

NOTE!
Unless told otherwise, Rails expects an action to render a template with the same name,
contained in a folder named after its controller. If this controller is an API responding with 204 (No Content),
which does not require a template, then this error will occur when trying to access it via browser,
since we expect an HTML template to be rendered for such requests. If that's the case, carry on.

The log shows:

Started GET "/en/admins/1/testmail" for 127.0.0.1 at 2020-03-05 08:28:00 +0100
Processing by Admins::AdminsController#testmail as HTML
  Parameters: {"locale"=>"en", "admin_id"=>"1"}
  Rendering test_mailer/testmail.text.erb within layouts/mailer
  Rendered test_mailer/testmail.text.erb within layouts/mailer (Duration: 0.1ms | Allocations: 4)
TestMailer#testmail: processed outbound mail in 2.0ms
Delivered mail [email protected] (59.0ms)
Date: Thu, 05 Mar 2020 08:28:00 +0100
From: [email protected]
To: [email protected]
Message-ID: <[email protected]>
Subject: Welcome to My Awesome Site
Mime-Version: 1.0
Content-Type: text/plain;
 charset=UTF-8
Content-Transfer-Encoding: 7bit

Welcome to example.com
===============================================
You have successfully signed up to example.com,
your username is: XXXX
To login to the site, just follow this link: .
Thanks for joining and have a great day!

Completed 406 Not Acceptable in 64ms (ActiveRecord: 0.0ms | Allocations: 3862)
ActionController::MissingExactTemplate (Admins::AdminsController#testmail is missing a template for request formats: text/html):
actionpack (6.0.2.1) lib/action_controller/metal/implicit_render.rb:45:in `default_render'
actionpack (6.0.2.1) lib/action_controller/metal/basic_implicit_render.rb:6:in `block in send_action'
actionpack (6.0.2.1) lib/action_controller/metal/basic_implicit_render.rb:6:in `tap'
actionpack (6.0.2.1) lib/action_controller/metal/basic_implicit_render.rb:6:in `send_action'
actionpack (6.0.2.1) lib/abstract_controller/base.rb:196:in `process_action'

One can see above that the template is rendered before the error occurs.

My Mailer class:

class TestMailer < ApplicationMailer
  def testmail
    mail(to: '[email protected]',
         subject: 'Welcome to My Awesome Site') do |format|
      format.text
    end
  end
end

Of course the template is placed in /app/views/test_mailer/testmail.text.erb.

My mail server config in development.rb is

I have mailcatcher running on localhost

config.action_mailer.raise_delivery_errors = true
config.action_mailer.perform_caching = false

config.action_mailer.smtp_settings = {
address: 'localhost',
port: 1025
}
config.action_mailer.delivery_method :smtp
config.action_mailer.perform_deliveries = true
config.action_mailer.raise_delivery_errors = false

I’m on a Centos 7, no special characters nor whitespaces in the whole Rails app path
Thanks for your investigations.

2

Answers


  1. You may try to generate your mailer in order to check you are not forgetting something:

    bundle exec rails generate mailer mailer_classname mailer_viewname
    
    Login or Signup to reply.
  2. the problem is not the email that is sent successfully according to the log

    the problem is you controller action Admins::AdminsController#testmail

    doesn´t have a template in the views to render whatever html when a email is successfully sent

    I suppose the path would be something like this:

    /app/views/admins/admins/testmail.html.erb
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search