Mailer Error Missing Template

Missing template layouts/mailer with {:locale=[:en], :formats=[:html],

If you don't already, you will need a folder within views called user_mailer and within that you will need a file for each of those methods (account_activation.html.erb & password_reset.html.erb). This is where the template of your email will be.

Missing template application_mailer/mailer with mailer. Searched in: * application_mailer

create mailer.html.erb
under app/views/application_mailers

mailer action need view to render so it is searching for application_mailers/mailer.html.erb which is missing I think

Action Mailer Missing Template error unless body is specified

You only have plain text template in place. What about the .html.erb?

Try this code to limit your mailer to only sending plain text emails if that's what you want:

def notify(contact)
@contact = contact
mail(to: 'text@example.com', subject: 'Notification') do |format|
format.text
end
end

Otherwise, if you want html emails, provide their template as well.

UPDATE

From the error text it is apparent that the mailer's layout template cannot be found. You have this in your mailer:

layout 'mailer'

This means any particular action template will be rendered as part of the mentioned layout template. Therefore you need this layout template in place. You can see that the mailer expects it to be called layouts/mailer and looks for it in app/views, which makes it

app/views/layouts/mailer.html.erb # for html emails
app/views/layouts/mailer.text.erb # for plain text emails

If you do not need a common layout for the emails, you can just remove the layout 'mailer' line and it should work.

Missing template layouts/CUSTOM_MAILER_NAME with {:locale=[:en]

The error is for missing layout for mailer.

Missing template layouts/test_mailer with 
{:locale=>[:en], :formats=>[:html], :variants=>[], :handlers=>[:raw, :erb,
:html, :builder, :ruby]}

In third line of mailers/test_mailer.rb the statement says layout 'test_mailer

It looks for test_mailer.html.erb in your views/layout folder. You have to create this file with simple HTML Body like:

<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<style>
/* Email styles need to be inline */
</style>
</head>

<body>
<%= yield %>
</body>
</html>

Now in mail_notification.html.erb only keep the email content and remove html body, it will be taken from layout file.

Update:
You might have confusion because name of your layout and your mailer class is same. Just for understanding you can rename your mailer layout name to mailer_layout:
ie:

class TestMailer < ActionMailer::Base
default from: 'test@gmail.com'
layout 'mailer_layout'

def mail_notification
...
end
end

Now you need following views:

app/views/layouts/mailer_layout.html.erb

app/views/test_mailer/mail_notification.html.erb

templates missing with mailer

Most likely you use layout 'mailer' in your ApplicationMailer class. Use existing layout or don't use layout at all.



Related Topics



Leave a reply



Submit