views:

541

answers:

5

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?

+7  A: 

I believe text/css should be OK

gonzo
+1  A: 

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.

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

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.

ndp
Including the css in the html is quite simple if you're doing it inside a Perl program.
larelogio
A: 

try using inline css ...it works

http://www.tizag.com/cssT/inline.php

ramkumar

ramkumar
A: 

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.

ppant