使 HTML 邮件稍微不那么痛苦。在 CSS 中写入代码并修正图像 URL。
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:
sudo gem install gemcutter sudo gem tumble
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
h2. Bugs / Todo
h2. Contributors
h2. 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.
暂无开放 Issues,或尚未同步最近议题。