Baike.dev
All toolsOnline toolsAI codingTrendingOpen sourceNewsSubmit
Log in
< Back to tools
M

mail_style

> 编程语言
Open source

Making HTML emails a little less painful. Writes css inline and corrects image urls.

191 stars0 likes1 views
WebsiteGitHub

About

Making HTML emails a little less painful. Writes css inline and corrects image urls.

h1. MailStyle

MailStyle tries to make sending HTML emails a little less painful.

For a more in depth introduction check out the "Blog Post":http://blog.purifyapp.com/2009/12/30/mailstyle-a-html-email-plugin-for-ruby-on-rails/

It was developed for use on "Purify: Awesome Bug & Issue Tracking":http://purifyapp.com

h2. Install

First install the dependencies:

sudo gem install nokogiri css_parser

Then install MailStyle to your rails app, either as a plugin:

script/plugin install http://github.com/purify/mail_style

Or you can install the gem:

Install gemcutter if you haven't already

sudo gem install gemcutter sudo gem tumble

Install MailStyle

sudo gem install mail_style

Then in your environment.rb file add:

config.gem "mail_style"

h2. Usage

Simply add the css method to your deliver actions:

class Notifier < ActionMailer::Base def welcome_email css :email

subject 'Welcome Aboard'
recipients '[email protected]'
from '[email protected]'
sent_on Time.now

end

def newsletter_email css [:email,:newsletter]

subject 'Newsletter'
recipients '[email protected]'
from '[email protected]'
sent_on Time.now

end end

This will look for a css file called email.css in your public/stylesheets folder. The css method can take either a string or a symbol. You can also pass the css file name with or without the .css extension.

h3. Styles in the email's HEAD

By default, <style> elements in the email document's <head> are processed and removed from the <head>.

Style elements with media="print" are ignored.

You can set a special data-immutable="true" attribute on <style> tags you do not want to be processed and removed from the document's <head>.

h2. Image URL Correcting

If you have default_url_options[:host] set in your mailer, then MailStyle will do it's best to make the urls of images absolute.

h4. In your mailer

ActionMailer::Base.default_url_options[:host] = "example.com"

h2. Features

  • Write CSS styles inline
  • Corrects image urls
  • SASS Support

h2. Bugs / Todo

  • Improve overall performance
  • Add support for less
  • Allow users to swap between css_parser and csspool

h2. Contributors

  • "Jim Neath":http://jimneath.org
  • "Lars Klevans":http://tastybyte.blogspot.com/
  • "Jonas Grimfelt":http://github.com/grimen
  • "Ben Johnson":http://www.binarylogic.com
  • "Istvan Hoka":http://istvanhoka.com/
  • "Voraz":http://blog.voraz.com.br

h2. License

(The MIT License)

Copyright © 2009-2010

  • "Jim Neath":http://jimneath.org

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the ‘Software’), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED ‘AS IS’, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Issues· 0 open

View all issuesOpen on GitHub

No open issues yet, or sync has not completed.

> Tags

Ruby

No comments yet. Be the first to share.

> Details

PublishedAug 1, 2026
UpdatedSep 18, 2026
Category编程语言
PricingOpen source

> Related tools

T
TypeScript
JavaScript 的超集,为前端与全栈提供静态类型
P
Python
通用编程语言,广泛用于 Web、数据与 AI
G
Go
Google 推出的简洁高效系统语言