Many email clients don\'t like linked CSS stylesheets, or even the embedded tag, but rather want the CSS to appear inline as style attributes on all y
I do not know of a complete, pre-packaged solution.
CSS::DOM's compute_style
is subject to pretty much the same caveats as emogrifier above. That module, in conjunction with HTML::TokeParser ought to be usable to cook up something.
Update: Here is a buggy mish-mash of things:
#!/usr/bin/perl
use strict;
use warnings;
use CSS::DOM;
use File::Slurp;
use HTML::DOM;
use HTML::TokeParser;
die "convert html_file css_file" unless @ARGV == 2;
my ($html_file, $css_file) = @ARGV;
my $html_parser = HTML::TokeParser->new($html_file)
or die "Cannot open '$html_file': $!";
my $sheet = CSS::DOM::parse( scalar read_file $css_file );
while ( my $token = $html_parser->get_token ) {
my $type = $token->[0];
my $text = $type eq 'T' ? $token->[1] : $token->[-1];
if ( $type eq 'S' ) {
unless ( skip( $token->[1] ) ) {
$text = insert_computed_style($sheet, $token);
}
}
print $text;
}
sub insert_computed_style {
my ($sheet, $token) = @_;
my ($tag, $attr, $attrseq) = @$token[1 .. 3];
my $doc = HTML::DOM->new;
my $element = $doc->createElement($tag);
for my $attr_name ( @$attrseq ) {
$element->setAttribute($attr_name, $attr->{$attr_name});
}
my $style = CSS::DOM::compute_style(
element => $element, user_sheet => $sheet
);
my @attrseq = (style => grep { lc $_ ne 'style' } @$attrseq );
$attr->{style} = $style->cssText;
my $text .= join(" ",
"<$tag",
map{ qq/$_='$attr->{$_}'/ } @attrseq );
$text .= '>';
return $text;
}
sub skip {
my ($tag) = @_;
$tag = lc $tag;
return 1 if $tag =~ /^(?:h(?:ead|tml)|link|meta|script|title)$/;
}
You can use CSS::Inliner
http://search.cpan.org/dist/CSS-Inliner/