Code Monkey home page Code Monkey logo

mail_style's Introduction

MailStyle

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

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"

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.

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"

Features

  • 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

Contributors

License

(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.

mail_style's People

Contributors

jimneath avatar ihoka avatar grimen avatar alexandrebini avatar

Stargazers

 avatar Voraz avatar

Watchers

Voraz avatar  avatar James Cloos avatar

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.