A summary of data about the Ruby ecosystem.

https://github.com/fphilipe/premailer-rails

CSS styled emails without the hassle.
https://github.com/fphilipe/premailer-rails

Keywords

css email gem inline-css rails ruby

Keywords from Contributors

activerecord activejob mvc rubygems background-jobs rubocop crash-reporting feature-flag ruby-gem nokogiri

Last synced: about 4 hours ago
JSON representation

Repository metadata

CSS styled emails without the hassle.

README.md

premailer-rails

CSS styled emails without the hassle.

Build Status
Gem Version
Code Climate

Introduction

This gem is a drop in solution for styling HTML emails with CSS without having
to do the hard work yourself.

Styling emails is not just a matter of linking to a stylesheet. Most clients,
especially web clients, ignore linked stylesheets or <style> tags in the HTML.
The workaround is to write all the CSS rules in the style attribute of each
tag inside your email. This is a rather tedious and hard to maintain approach.

Premailer to the rescue! The great premailer gem applies all CSS rules to each
matching HTML element by adding them to the style attribute. This allows you
to keep HTML and CSS in separate files, just as you're used to from web
development, thus keeping your sanity.

This gem is an adapter for premailer to work with actionmailer out of the box.
Actionmailer is the email framework used in Rails, which also works outside of
Rails. Although premailer-rails has certain Rails specific features, it also
works in the absence of Rails
making it compatible with other frameworks such
as sinatra.

How It Works

premailer-rails works with actionmailer by registering a delivery hook. This
causes all emails that are delivered to be processed by premailer-rails. This
means that by simply including premailer-rails in your Gemfile you'll get
styled emails without having to set anything up.

Whenever premailer-rails processes an email, it collects the URLs of all linked
stylesheets (<link rel="stylesheet" href="css_url">). Then, for each of these
URLs, it tries to get the content through a couple of strategies. As long as
a strategy does not return anything, the next one is used. The strategies
available are:

  • :filesystem: If there's a file inside public/ with the same path as in
    the URL, it is read from disk. E.g. if the URL is
    http://cdn.example.com/assets/email.css the contents of the file located
    at public/assets/email.css gets returned if it exists.

  • :asset_pipeline: If Rails is available and the asset pipeline is enabled,
    the file is retrieved through the asset pipeline. E.g. if the URL is
    http://cdn.example.com/assets/email-fingerprint123.css, the file
    email.css is requested from the asset pipeline. That is, the fingerprint
    and the prefix (in this case assets is the prefix) are stripped before
    requesting it from the asset pipeline.

  • :network: As a last resort, the URL is simply requested and the response
    body is used. This is useful when the assets are not bundled in the
    application and only available on a CDN. On Heroku e.g. you can add assets
    to your .slugignore causing your assets to not be available to the app
    (and thus resulting in a smaller app) and deploy the assets to a CDN such
    as S3/CloudFront.

You can configure which strategies you want to use as well as specify their
order. Refer to the Configuration section for more on this.

Note that the retrieved CSS is cached when the gem is running with Rails in
production.

Installation

Simply add the gem to your Gemfile:

gem 'premailer-rails'

premailer-rails and premailer require a gem that is used to parse the email's
HTML. For a list of supported gems and how to select which one to use, please
refer to the Adapter
section
of premailer. Note
that there is no hard dependency from either gem so you should add one yourself.
Also note that this gem is only tested with nokogiri.

Configuration

Premailer itself accepts a number of options. In order for premailer-rails to
pass these options on to the underlying premailer instance, specify them
as follows (in Rails you could do that in an initializer such as
config/initializers/premailer_rails.rb):

Premailer::Rails.config.merge!(preserve_styles: true, remove_ids: true)

For a list of options, refer to the premailer documentation. The default
configs are:

{
  input_encoding: 'UTF-8',
  generate_text_part: true,
  strategies: [:filesystem, :asset_pipeline, :network]
}

If you don't want to automatically generate a text part from the html part, set
the config :generate_text_part to false.

Note that the options :with_html_string and :css_string are used internally
by premailer-rails and thus will be overridden.

If you're using this gem outside of Rails, you'll need to call
Premailer::Rails.register_interceptors manually in order for it to work. This
is done ideally in some kind of initializer, depending on the framework you're
using.

premailer-rails reads all stylesheet <link> tags, inlines the linked CSS
and removes the tags. If you wish to ignore a certain tag, e.g. one that links to
external fonts such as Google Fonts, you can add a data-premailer="ignore"
attribute.

Usage

premailer-rails processes all outgoing emails by default. If you wish to skip
premailer for a certain email, simply set the :skip_premailer header:

class UserMailer < ActionMailer::Base
  def welcome_email(user)
    mail to: user.email,
         subject: 'Welcome to My Awesome Site',
         skip_premailer: true
  end
end

Note that the mere presence of this header causes premailer to be skipped, i.e.,
even setting skip_premailer: false will cause premailer to be skipped. The
reason for that is that the skip_premailer is a simple header and the value is
transformed into a string, causing 'false' to become truthy.

Emails are only processed upon delivery, i.e. when calling #deliver on the
email, or when previewing them in
rails
.
If you wish to manually trigger the inlining, you can do so by calling the hook:

mail = SomeMailer.some_message(args)
Premailer::Rails::Hook.perform(mail)

This will modify the email in place, useful e.g. in tests.

Supported Rails Versions

This gem is tested on Rails versions 5 through 7.

For Rails 7, it support both the classical Sprockets asset pipeline as well as the new Propshaft gem.

If you're looking to integrate with Webpacker, check out these instructions.

Small Print

Author

Philipe Fatio (@fphilipe)

License

premailer-rails is released under the MIT license. See the license file.


Owner metadata


GitHub Events

Total
Last Year

Committers metadata

Last synced: 2 days ago

Total Commits: 335
Total Committers: 57
Avg Commits per committer: 5.877
Development Distribution Score (DDS): 0.227

Commits in past year: 0
Committers in past year: 0
Avg Commits per committer in past year: 0.0
Development Distribution Score (DDS) in past year: 0.0

Name Email Commits
Philipe Fatio me@p****e 259
Kir Shatrov s****v@m****m 7
Javier Julio j****l@g****m 7
Rolly Fordham r****y@l****z 5
wonda-tea-coffee l****t@g****m 2
Rafael Masson r****n@g****m 2
Jonathan Goldman me@j****m 2
Florian Dütsch m****l@f****e 2
Andrew Hubbs a****w@h****s 1
Atinder Singh a****a@g****m 1
Bitdeli Chef c****f@b****m 1
Brandon Hilkert b****t@g****m 1
Christian Schmidt g****b@c****k 1
Dmytrii Nagirniak d****r@g****m 1
Earle Clubb e****b@v****m 1
Sven Winkler s****r@n****e 1
Steve Dee s****e@c****m 1
Sijawusz Pur Rahnama s****a@p****m 1
Said Kaldybaev s****v@m****m 1
Roman Marynchak r****k@g****m 1
Pete Hopkins p****s@t****m 1
Michael Reinsch m****l@m****m 1
Mauricio Menegaz m****z@t****r 1
Mark Edmondson m****k@g****m 1
Marius Bobin m****n@g****m 1
Greg Woodward & Justin Richard p****n@p****m 1
Jonathan del Strother j****r@a****m 1
Kai Schlichting l****t@g****e 1
zdenal n****z@g****m 1
jlxw j****n@j****m 1
and 27 more...

Committer domains:


Issue and Pull Request metadata

Last synced: 11 days ago

Total issues: 55
Total pull requests: 55
Average time to close issues: 3 months
Average time to close pull requests: 3 months
Total issue authors: 51
Total pull request authors: 43
Average comments per issue: 3.84
Average comments per pull request: 1.91
Merged pull request: 25
Bot issues: 0
Bot pull requests: 0

Past year issues: 2
Past year pull requests: 0
Past year average time to close issues: about 17 hours
Past year average time to close pull requests: N/A
Past year issue authors: 2
Past year pull request authors: 0
Past year average comments per issue: 0.5
Past year average comments per pull request: 0
Past year merged pull request: 0
Past year bot issues: 0
Past year bot pull requests: 0

More stats: https://issues.ecosyste.ms/repositories/lookup?url=https://github.com/fphilipe/premailer-rails

Top Issue Authors

  • ghost (3)
  • robsdudeson (2)
  • jmuheim (2)
  • curtp (1)
  • derekwheel (1)
  • eric1234 (1)
  • davidwessman (1)
  • Saidbek (1)
  • dlouzan (1)
  • n-rodriguez (1)
  • aguynamedben (1)
  • javierjulio (1)
  • irene-chi19 (1)
  • kimardenmiller (1)
  • hadifarnoud (1)

Top Pull Request Authors

  • kirs (7)
  • fphilipe (4)
  • javierjulio (3)
  • wonda-tea-coffee (3)
  • stanhu (2)
  • ywen (1)
  • sebjacobs (1)
  • Saidbek (1)
  • AnrichVS (1)
  • tilthouse (1)
  • apauly (1)
  • maschwenk (1)
  • ThriceGood (1)
  • caseyprovost (1)
  • mbobin (1)

Top Issue Labels

  • feature request (1)

Top Pull Request Labels


Package metadata

gem.coop: premailer-rails

This gem brings you the power of the premailer gem to Rails without any configuration needs. Create HTML emails, include a CSS file as you do in a normal HTML document and premailer will inline the included CSS.

  • Homepage: https://github.com/fphilipe/premailer-rails
  • Documentation: http://www.rubydoc.info/gems/premailer-rails/
  • Licenses: MIT
  • Latest release: 1.12.0 (published over 3 years ago)
  • Last Synced: 2026-03-01T21:01:30.388Z (2 days ago)
  • Versions: 25
  • Dependent Packages: 0
  • Dependent Repositories: 0
  • Downloads: 102,374,661 Total
  • Docker Downloads: 451,530,016
  • Rankings:
    • Dependent repos count: 0.0%
    • Dependent packages count: 0.0%
    • Average: 0.123%
    • Docker downloads count: 0.244%
    • Downloads: 0.247%
  • Maintainers (1)
rubygems.org: premailer-rails

This gem brings you the power of the premailer gem to Rails without any configuration needs. Create HTML emails, include a CSS file as you do in a normal HTML document and premailer will inline the included CSS.

  • Homepage: https://github.com/fphilipe/premailer-rails
  • Documentation: http://www.rubydoc.info/gems/premailer-rails/
  • Licenses: MIT
  • Latest release: 1.12.0 (published over 3 years ago)
  • Last Synced: 2026-03-02T11:02:09.726Z (1 day ago)
  • Versions: 25
  • Dependent Packages: 15
  • Dependent Repositories: 4,603
  • Downloads: 102,391,260 Total
  • Docker Downloads: 451,530,016
  • Rankings:
    • Docker downloads count: 0.303%
    • Downloads: 0.317%
    • Dependent repos count: 0.464%
    • Average: 0.885%
    • Stargazers count: 1.248%
    • Dependent packages count: 1.364%
    • Forks count: 1.612%
  • Maintainers (1)
gem.coop: premailer-rails3

This gem brings you the power of the premailer gem to Rails without any configuration needs. Create HTML emails, include a CSS file as you do in a normal HTML document and premailer will inline the included CSS.

  • Homepage: https://github.com/fphilipe/premailer-rails
  • Documentation: http://www.rubydoc.info/gems/premailer-rails3/
  • Licenses: mit
  • Latest release: 1.3.2 (published almost 13 years ago)
  • Last Synced: 2026-03-02T09:33:21.225Z (1 day ago)
  • Versions: 10
  • Dependent Packages: 0
  • Dependent Repositories: 0
  • Downloads: 239,196 Total
  • Rankings:
    • Dependent repos count: 0.0%
    • Dependent packages count: 0.0%
    • Average: 1.958%
    • Downloads: 5.875%
  • Maintainers (1)
rubygems.org: premailer-rails3

This gem brings you the power of the premailer gem to Rails without any configuration needs. Create HTML emails, include a CSS file as you do in a normal HTML document and premailer will inline the included CSS.

  • Homepage: https://github.com/fphilipe/premailer-rails
  • Documentation: http://www.rubydoc.info/gems/premailer-rails3/
  • Licenses: mit
  • Latest release: 1.3.2 (published almost 13 years ago)
  • Last Synced: 2026-02-28T13:01:41.593Z (3 days ago)
  • Versions: 10
  • Dependent Packages: 2
  • Dependent Repositories: 34
  • Downloads: 239,192 Total
  • Rankings:
    • Stargazers count: 1.245%
    • Forks count: 1.603%
    • Average: 3.503%
    • Dependent repos count: 4.253%
    • Downloads: 5.146%
    • Dependent packages count: 5.267%
  • Maintainers (1)
proxy.golang.org: github.com/fphilipe/premailer-rails

ubuntu-23.10: ruby-premailer-rails

  • Homepage: https://github.com/fphilipe/premailer-rails
  • Licenses:
  • Latest release: 1.10.3-4 (published 18 days ago)
  • Last Synced: 2026-02-13T18:29:52.891Z (18 days ago)
  • Versions: 1
  • Dependent Packages: 0
  • Dependent Repositories: 0
  • Rankings:
    • Dependent repos count: 0.0%
    • Dependent packages count: 0.0%
    • Average: 100%
debian-11: ruby-premailer-rails

  • Homepage: https://github.com/fphilipe/premailer-rails
  • Documentation: https://packages.debian.org/bullseye/ruby-premailer-rails
  • Licenses:
  • Latest release: 1.10.3-3 (published 21 days ago)
  • Last Synced: 2026-02-13T08:23:29.015Z (18 days ago)
  • Versions: 1
  • Dependent Packages: 0
  • Dependent Repositories: 0
  • Rankings:
    • Dependent repos count: 0.0%
    • Dependent packages count: 0.0%
    • Average: 100%
ubuntu-20.04: ruby-premailer-rails

  • Homepage: https://github.com/fphilipe/premailer-rails
  • Licenses:
  • Latest release: 1.10.3-2 (published 18 days ago)
  • Last Synced: 2026-02-13T07:20:12.807Z (18 days ago)
  • Versions: 1
  • Dependent Packages: 0
  • Dependent Repositories: 0
  • Rankings:
    • Dependent repos count: 0.0%
    • Dependent packages count: 0.0%
    • Average: 100%
ubuntu-22.04: ruby-premailer-rails

  • Homepage: https://github.com/fphilipe/premailer-rails
  • Licenses:
  • Latest release: 1.10.3-3 (published 18 days ago)
  • Last Synced: 2026-02-13T13:23:10.442Z (18 days ago)
  • Versions: 1
  • Dependent Packages: 0
  • Dependent Repositories: 0
  • Rankings:
    • Dependent repos count: 0.0%
    • Dependent packages count: 0.0%
    • Average: 100%
ubuntu-23.04: ruby-premailer-rails

  • Homepage: https://github.com/fphilipe/premailer-rails
  • Licenses:
  • Latest release: 1.10.3-3 (published 20 days ago)
  • Last Synced: 2026-02-11T06:46:58.703Z (20 days ago)
  • Versions: 1
  • Dependent Packages: 0
  • Dependent Repositories: 0
  • Rankings:
    • Dependent repos count: 0.0%
    • Dependent packages count: 0.0%
    • Average: 100%
debian-12: ruby-premailer-rails

  • Homepage: https://github.com/fphilipe/premailer-rails
  • Documentation: https://packages.debian.org/bookworm/ruby-premailer-rails
  • Licenses:
  • Latest release: 1.10.3-4~deb12u1 (published 19 days ago)
  • Last Synced: 2026-02-12T23:37:37.666Z (19 days ago)
  • Versions: 1
  • Dependent Packages: 0
  • Dependent Repositories: 0
  • Rankings:
ubuntu-24.04: ruby-premailer-rails

  • Homepage: https://github.com/fphilipe/premailer-rails
  • Licenses:
  • Latest release: 1.10.3-4 (published 25 days ago)
  • Last Synced: 2026-02-06T15:46:50.201Z (25 days ago)
  • Versions: 1
  • Dependent Packages: 0
  • Dependent Repositories: 0
  • Rankings:
ubuntu-24.10: ruby-premailer-rails

  • Homepage: https://github.com/fphilipe/premailer-rails
  • Licenses:
  • Latest release: 1.12.0-1 (published 22 days ago)
  • Last Synced: 2026-02-09T17:04:28.309Z (22 days ago)
  • Versions: 1
  • Dependent Packages: 0
  • Dependent Repositories: 0
  • Rankings:

Dependencies

Gemfile rubygems
  • arel >= 0
  • byebug >= 0
  • racc >= 0
  • rails >= 0
  • rubysl >= 0
  • sprockets-rails >= 0
premailer-rails.gemspec rubygems
  • nokogiri >= 0 development
  • rspec ~> 3.3 development
  • actionmailer >= 3
  • premailer ~> 1.7, >= 1.7.9
.github/workflows/test.yml actions
  • actions/checkout v3 composite
  • ruby/setup-ruby v1 composite
examples/rails5/Gemfile rubygems
  • premailer-rails >= 0
  • rails ~> 5.2, >= 5.2.8.1
examples/rails6/Gemfile rubygems
  • premailer-rails >= 0
  • rails ~> 6.1.7
examples/rails7-propshaft/Gemfile rubygems
  • premailer-rails >= 0
  • propshaft >= 0
  • rails ~> 7.0.4
examples/rails7-sprockets/Gemfile rubygems
  • premailer-rails >= 0
  • rails ~> 7.0.4
  • sprockets-rails >= 0

Score: 32.34279006224437