3

I am working on a script that e-mails some formatted html and images to recipients. Using MIME::Lite, I figured out a way to send the css file and the image file it uses as attachments. The image comes out at the end of the mail message - as an attachment. The following line appears to work:

<link href="cid:style.css" rel="stylesheet" type="text/css" />

My question is what should be the syntax for the following lines (in the file style.css)? Following does not work.

body {
        background-image:url("cid:bgLine.png");
        background-repeat:repeat-x;
}

Furthermore, how can I stop the mail client from showing the image by itself? Script I am using follows:

my $msg = MIME::Lite->new( From =>"from\@company\.com",
                               To => "to\@company\.com",,
                               Subject =>"Action Required",
                               Disposition =>'inline',
                               Type    =>'multipart/related');
$msg->attach(Type => 'text/html', Data => qq{@htFileContents});
$msg->attach(Type => 'text/html', Id => $cssFileName, Data => qq{@cssFileContents});
$msg->attach(Type => 'image/png', Id => $imageFile, Path => $imageFile);
$msg->send("sendmail","/usr/sbin/sendmail -t");

Having the mail client access an URL for the css or the image file from an http server is not an option. The e-mail needs to be self-contained. TIA for an example showing the syntax.

Manidip Sengupta
  • 3,573
  • 5
  • 25
  • 27

2 Answers2

0

This won't really work. Even if by some miracle you were able to get your attachments to see and talk to each other, Outlook won't support background images, Gmail will strip out your linked css file and any embedded css, and hotmail will not support css backgrounds.

Sounds like you need to host an HTML email somewhere that accepts dynamic parts, and trigger the send from within your application, passing it the dynamic parts to fill in before sending. Check out a tool like Lyris Listmanager or something.

DoubleA
  • 1,636
  • 14
  • 28
0

There is no connection between the title and the posted question above.

Anyway, in order to send emails, showing safely images, that are attached in the email, it just not enough to refer the images with some cid: URLs.

Attaching the images to the email has the following specifics:

  • Replace the external URLs to images with the URLs of an attachments in the email.
  • The email to generate is not just multipart/mixed what is construed by default of JavaMail, but MIME multipart/related type, in order to allow the email client to use the images.
  • The attachments for the images must be have
    • Content-Disposition: inline; filename=... header, in order they not to be shown as attached files, but to allow the email client to use them.
    • ContentID:unique-name@domain header, where the unique-name and domain have to be replaced with actual values and keep < and >! Example: ContentId: logo.png@paysafe.com
  • The references in the HTML part of the email message (the message body) happens through cid:content-id URLs, where content-id is the the value of the ContentId header of the attachment holding the image Example:

References:

Community
  • 1
  • 1
Rusi Popov
  • 377
  • 1
  • 6