MailStyle tries to make sending HTML emails a little less painful.
For a more in depth introduction check out the Blog Post
It was developed for use on Purify: Awesome Bug & Issue Tracking
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:
Simply add the
css method to your deliver actions:
class Notifier < ActionMailer::Base def welcome_email css :email subject 'Welcome Aboard' recipients 'firstname.lastname@example.org' from 'email@example.com' sent_on Time.now end def newsletter_email css [:email,:newsletter] subject 'Newsletter' recipients 'firstname.lastname@example.org' from 'email@example.com' 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.
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>.
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.
In your mailer
ActionMailer::Base.default_url_options[:host] = "example.com"
- Write CSS styles inline
- Corrects image urls
- SASS Support
Bugs / Todo
- Improve overall performance
- Add support for less
- Allow users to swap between css_parser and csspool
(The MIT License)
Copyright © 2009-2010
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.