Ruby Icon

Premailer - prep your HTML email by inlining CSS

At what must be the nexus of the open source universe, we’re posting a cool project from Alex Dunae aka theCHANGELOG. Premailer is a Ruby library to help you prep your HTML email templates for better viewing in most web clients by:

  • making all your CSS inline
  • changing relative links to absolute links
  • moving any CSS pseudo-classes (like :hover) to the <head>
  • checking your HTML and CSS for compatibiliy with e-mail programs
  • creating a plain-text version of your message

To use:

sudo gem install premailer

and then

premailer ='', :warn_level => Premailer::Warnings::SAFE)

# Write the HTML output
fout ="output.html", "w")
fout.puts premailer.to_inline_css

# Write the plain-text output
fout ="ouput.txt", "w")
fout.puts premailer.to_plain_text

# Output any CSS warnings
premailer.warnings.each do |w|
  puts "#{w[:message]} (#{w[:level]}) may not render properly in #{w[:clients]}"

For the terminally challenged there’s also a nifty web interface

[Source on GitHub] [Home page]

0:00 / 0:00