# Layout on Email

**URL:** <https://www.ruby-forum.com/t/layout-on-email/191710>\
**Category:** Rails\
**Created:** [July 16, 2010, 4:02pm UTC](https://www.ruby-forum.com/t/layout-on-email/191710 "2010-07-16T16:02:00Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Rawlins](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/e79b87/32.png) [@Rawlins](https://www.ruby-forum.com/u/Rawlins)\
**Post date:** [July 16, 2010, 4:02pm UTC](https://www.ruby-forum.com/t/layout-on-email/191710/1 "2010-07-16T16:02:00Z")

</div>

Hello G.s,

Very new to Rails an enjoying myself a great deal. Been playing around  
with the ActionMailer today sending emails. I’m currently sending a  
multipart email using the naming conventions for my views to send both  
an HTML and a TEXT version of the content.

contact.text.html.erb  
contact.text.plain.erb

and this is working just perfectly. What I’m now looking to do is  
apply a layout to the HTML emails that are sent from the system, so  
that all have a uniform look and feel.

I understand how I can apply a layout to a standard HTML view which  
gets rendered in the browser but I’m struggling to figure out how this  
can be done, if at all, for HTML emails.

I’d appreciate any help you can offer, if you need any more  
information then please let me know.

Thanks,

Robert

---

<div class="post-metadata">

**Author:** ![Rawlins](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/e79b87/32.png) [@Rawlins](https://www.ruby-forum.com/u/Rawlins)\
**Post date:** [July 17, 2010, 2:19pm UTC](https://www.ruby-forum.com/t/layout-on-email/191710/2 "2010-07-17T14:19:30Z")

</div>

Hello All,

I’ve been looking into this a little more this morning and found this  
in the docs

> **[Action Mailer Basics — Ruby on Rails Guides](https://guides.rubyonrails.org/action_mailer_basics.html#action-mailer-layouts)**
>
> Action Mailer BasicsThis guide provides you with all you need to get started in sending emails from your application, and many internals of Action Mailer. It also covers how to test your mailers.After reading this guide, you will know: How to send...

This suggests that I should be able to create a layout file with a  
certain naming convention that should be picked up when the mail is  
rendered.

My mailer class i defined like this: [http://pastebin.com/BQ0n6Fm4](http://pastebin.com/BQ0n6Fm4)

I’ve then created the layout /layouts/  
notifications\_mailer.text.html.erb

However, when sending the mails the layout is still not picked up. I’m  
not receiving any error messages either.

I appreciate any further input people can offer.

Thanks,

Robert

---

<div class="post-metadata">

**Author:** ![Rawlins](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/e79b87/32.png) [@Rawlins](https://www.ruby-forum.com/u/Rawlins)\
**Post date:** [July 17, 2010, 2:28pm UTC](https://www.ruby-forum.com/t/layout-on-email/191710/3 "2010-07-17T14:28:16Z")

</div>

Hi Robert,

On Sat, Jul 17, 2010 at 7:18 AM, Rawlins [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> I’ve then created the layout /layouts/  
> notifications\_mailer.text.html.erb
> 
> However, when sending the mails the layout is still not picked up. I’m  
> not receiving any error messages either.

Have you tried explicitly specifying the layout in your mailer class?

layout ‘notifications’

Best regards,  
Bill

---

<div class="post-metadata">

**Author:** ![Rawlins](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/e79b87/32.png) [@Rawlins](https://www.ruby-forum.com/u/Rawlins)\
**Post date:** [July 19, 2010, 11:43am UTC](https://www.ruby-forum.com/t/layout-on-email/191710/4 "2010-07-19T11:43:29Z")

</div>

Hello Bill,

I’ve now solved the issue, although still confused.

I followed your advice of adding the explicite statement but simply  
got an error saying that /layouts/notifications.erb was no present.

I then removed the explicite statement and changes the name of my  
layout (contradictory to the docs) from:

/layouts/notifications\_mailer.text.html.erb

to

/layouts/notifications.text.html.erb

and it all sprung into life and appears to be working just fine! go  
figure! :-s My only guess is that the docs is based on the assumption  
that my mailer class is called NotificationsMailer and not just  
Notifications?

Either way the docs confused me a little, however, with your help I’m  
now up and running.

Thanks,

Robert
