GithubHelp home page GithubHelp logo

qpc-github / actionmailer_inline_css Goto Github PK

View Code? Open in Web Editor NEW

This project forked from premailer/actionmailer_inline_css

1.0 2.0 1.0 43 KB

Seamlessly integrate Alex Dunae's premailer with ActionMailer.

Home Page: http://madebynathan.com

License: MIT License

Ruby 100.00%

actionmailer_inline_css's Introduction

ActionMailer Inline CSS TravisCI

Seamlessly integrate Alex Dunae's premailer gem with ActionMailer.

Problem?

Gmail doesn't support <style> or <link> tags for HTML emails. Other webmail clients also have problems with <link> tags.

This means that CSS must be inlined on each element, otherwise the email will not be displayed correctly in every client.

Solution

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

From http://premailer.dialect.ca/:

  • 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('')

This 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.)

NOTE:

The current version of premailer doesn't support UTF-8, so I have written a small workaround to enforce it. This works for both Ruby 1.9 and 1.8.

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.

Example

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

<%= stylesheet_link_tag '/stylesheets/mailers/build_mailer' %>

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

More Info

See this Guide to CSS support in email from campaignmonitor.com for more info about CSS in emails.

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

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.