4

I am using following code to create and send email through CGI perl. The images get attached properly, but the css files do not.

  my $msg = new MIME::Lite(
            From    => $from,
            To      => $to_list,
            Subject => "My subject",
            Type    => 'text/html',  # 'multipart/mixed'
            Data    => $body
           );
 $msg->attach(Type => 'multipart/mixed',      Path => $DOCS_URL . "/fonts-min.css");
 $msg->attach(Type => 'multipart/mixed',      Path => $DOCS_URL . "/eat.css");
 $msg->attach(Type => 'multipart/mixed',      Path => $DOCS_URL . "/site_styles2.css");
 $msg->attach(Type => 'multipart/mixed',      Path => $DOCS_URL . "/calendar_layout.css");
 $msg->attach(Type => 'multipart/mixed',      Path => $DOCS_URL . "/errnacc.css");
 $msg->attach(Type => 'image/png',    Path => $DOCS_URL . "/separator.gif");
 $msg->attach(Type => 'image/png',    Path => $DOCS_URL . "/trans_pixel.gif");
 $msg->attach(Type => 'image/png',    Path => $DOCS_URL . "/itg_side.gif");

 $msg->send();

The images get attached properly, but the css files are not attached at all. Any idea what 'Type' should be used to attach CSS files? Or is there any other problem?

6 Answers 6

7

I believe text/css should be OK

Sign up to request clarification or add additional context in comments.

Comments

6

From my tests, many email clients simply remove all the head elements before displaying an email message. Therefore, using external style sheets isn't feasible if you have to support a wide range of email clients.

My advice is to include styling directly into the HTML, as painful as that is.

1 Comment

Including the css in the html is quite simple if you're doing it inside a Perl program.
2

I have to say, if what you're trying to do with your script is send HTML-formatted email, even if you get the CSS files sent as attachments, it's not going to work.

The only way to do this with any confidence at all is to send HTML with all external files linked using absolute URLs. And even then it won't work the way you expect it to.

1 Comment

This may not work for someone reading the message off-line or with on-the-fly access disabled.
2

Try using inline css ...it works (see http://www.tizag.com/cssT/inline.php)

Comments

0

I think you already got your answer but in my opinion good way is, instead of putting html code directly, use some html based mail envelope having message and placeholders in separate html file and then parse and replace placeholders so that you can use CSS easily and i think it will be easy to maintain too.

Comments

0

just came across same issue. you may try this tool, http://templates.mailchimp.com/resources/inline-css/ remember to save the copy of original template in case you need to update

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.