Skip to content
This repository


Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Seamlessly integrate Alex Dunae's premailer with ActionMailer.

tag: 1.1.0

Fetching latest commit…


Cannot retrieve the latest commit at this time

Octocat-spinner-32 lib
Octocat-spinner-32 test
Octocat-spinner-32 .gitignore
Octocat-spinner-32 Gemfile
Octocat-spinner-32 Rakefile
Octocat-spinner-32 actionmailer_inline_css.gemspec

ActionMailer Inline CSS TravisCI

Seamlessly integrate Alex Dunae's premailer gem with ActionMailer.


The Guide to CSS support in email from shows that Gmail doesn't support <style> tags.

Thus, the only correct way to send HTML emails is when CSS is inlined on each element.

Email Client Popularity:

Outlook 27.62%
iOS Devices 16.01%
Hotmail 12.14%
Apple Mail 11.13%
Yahoo! Mail 9.54%
Gmail 7.02%

Gmail may only make up 7% of all email clients, but it's a percentage you can't ignore!


Inlining CSS is a pain to do by hand, and that's where the premailer gem comes in.


  • CSS styles are converted to inline style attributes. Checks style and link[rel=stylesheet] tags and preserves existing inline attributes.
  • Relative paths are converted to absolute paths. Checks links in href, src and CSS url('')

The actionmailer_inline_css gem is a tiny integration between ActionMailer and premailer.

Inspiration comes from @fphilipe's premailer-rails3 gem, but I wasn't completely happy with it's conventions.

Installation & Usage

To use this in your Rails app, simply add gem "actionmailer_inline_css" to your Gemfile.

  • If you already have an HTML email template, all CSS will be automatically inlined.
  • If you don't include a text email template, premailer will generate one from the HTML part. (Having said that, it is recommended that you write your text templates by hand.)

Including CSS in Mail Templates

You can use the stylesheet_link_tag helper to add stylesheets to your mailer layouts. actionmailer_inline_css contains a premailer override that properly handles these CSS URIs.


Add the following line to the <head> section of app/views/layouts/build_mailer.html.erb:

<%= stylesheet_link_tag 'mailers/build_mailer' %>

This will add a stylesheet link for /stylesheets/mailers/build_mailer.css. Premailer will then inline the CSS from that file, and remove the link tag.

Something went wrong with that request. Please try again.