Question : Unix MIME sendmail -- How to attach .gif to embed in html-formatted email

I am producing a report in HTML format and sending it as an email via sendmail.  I would like to embed an .gif file.

The following line works: (cat header.txt body.html middle.txt image.gif footer.txt) | sendmail ""

I can't figure out the proper MIME syntax for the message.  Currently I receive the gif as a separate attachment but the attachment file is garbage.

Thanks.
Code Snippet:
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
header.txt:
 
From: 
To: 
Subject: 
Mime-Version: 1.0;
Content-Type: multipart/mixed; boundary="blah"
 
This is a message with muliple parts in MIME format.
 
--blah
Content-Type: text/html 
 
 
middle.txt:
 
--blah
Content-Type: image/gif; name=""
Content-Disposition: attachment; filename=""
Content-Transfer-Encoding: 8bit
 
 
footer.txt:
 
--blah--

Answer : Unix MIME sendmail -- How to attach .gif to embed in html-formatted email

MIME::Lite is the defacto-standard for sending MIME emails with Perl.

See http://search.cpan.org/~rjbs/MIME-Lite-3.027/lib/MIME/Lite.pm

1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
#!/usr/bin/perl
use MIME::Lite;
 
    $msg = MIME::Lite->new(
         To      =>'[email protected]',
         Subject =>'HTML with in-line images!',
         Type    =>'multipart/related'
    );
    $msg->attach(
        Type => 'text/html',
        Data => qq{
            <body>
                Here's <i>my</i> image:
                <img src="cid:myimage.gif">
            </body>
        },
    );
    $msg->attach(
        Type => 'image/gif',
        Id   => 'myimage.gif',
        Path => '/path/to/somefile.gif',
    );
 
    $msg->send();
Random Solutions  
 
programming4us programming4us