# Mailer layouts , how to link to a css file

**URL:** <https://www.ruby-forum.com/t/mailer-layouts-how-to-link-to-a-css-file/157797>\
**Category:** Rails\
**Created:** [January 15, 2009, 12:43pm UTC](https://www.ruby-forum.com/t/mailer-layouts-how-to-link-to-a-css-file/157797 "2009-01-15T12:43:21Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![kadoudal](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/f0a364/32.png) [@kadoudal](https://www.ruby-forum.com/u/kadoudal)\
**Post date:** [January 15, 2009, 12:43pm UTC](https://www.ruby-forum.com/t/mailer-layouts-how-to-link-to-a-css-file/157797/1 "2009-01-15T12:43:21Z")

</div>

I can send html emails using the new layouts feature

using inline style, there is no problem to get a nice display…  
but what if ?

i would like to link to a css file , … which king of link ? to  
public/stylesheets/email.css

if there is any relative image in the css for a background url ?  
like

#header {  
background: #ffcc00 url(…/…/…/images/logo.png) no-repeat 2px;  
}

thanks for you help ?

---

<div class="post-metadata">

**Author:** ![kadoudal](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/f0a364/32.png) [@kadoudal](https://www.ruby-forum.com/u/kadoudal)\
**Post date:** [January 15, 2009, 2:35pm UTC](https://www.ruby-forum.com/t/mailer-layouts-how-to-link-to-a-css-file/157797/2 "2009-01-15T14:35:08Z")

</div>

On Thu, Jan 15, 2009 at 3:43 AM, Kad K.  
[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> i would like to link to a css file , … which king of link ? to  
> public/stylesheets/email.css

Nothing to do with RoR, but you need to provide absolute, complete  
URLs, e.g. ‘[http://example.com/stylesheets/email.css](http://example.com/stylesheets/email.css)’.

> if there is any relative image in the css for a background url ?

Same deal,

> background: #ffcc00 url([http://example.com/images/logo.png](http://example.com/images/logo.png)) no-repeat 2px;

## HTH,

Hassan S. ------------------------ removed\_email\_address@domain.invalid

---

<div class="post-metadata">

**Author:** ![kadoudal](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/f0a364/32.png) [@kadoudal](https://www.ruby-forum.com/u/kadoudal)\
**Post date:** [January 15, 2009, 2:50pm UTC](https://www.ruby-forum.com/t/mailer-layouts-how-to-link-to-a-css-file/157797/3 "2009-01-15T14:50:48Z")

</div>

Hassan S. wrote:

> On Thu, Jan 15, 2009 at 3:43 AM, Kad K.  
> [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:
> 
> > i would like to link to a css file , … which king of link ? to  
> > public/stylesheets/email.css
> 
> Nothing to do with RoR, but you need to provide absolute, complete  
> URLs, e.g. ‘[http://example.com/stylesheets/email.css](http://example.com/stylesheets/email.css)’.
> 
> > if there is any relative image in the css for a background url ?
> 
> Same deal,
> 
> > background: #ffcc00 url([http://example.com/images/logo.png](http://example.com/images/logo.png)) no-repeat 2px;
> 
> ## HTH,
> 
> Hassan S. ------------------------ removed\_email\_address@domain.invalid

Thanks a lot … I’ll stop my tests… (was trying various option)  
;-)) !

btw: discovered a bug using multiparts with layout ( the plain text get  
the html source code…) with a nice trick to be inserted in the  
environment.rb … in case someone reads this post

module ActionMailer  
class Base  
private  
def candidate\_for\_layout?(options)  
(!options[:file] || options[:file].content\_type != ‘text/plain’)  
&& !@template.send(:\_exempt\_from\_layout?, default\_template\_name)  
end  
end  
end

thanks again !
