Jonathan has asked for the wisdom of the Perl Monks concerning the following question:

I recently found this article about sending HTML e-mails from my Unix box to MS mail/Outlook clients. This has made a great difference to my automatically generated system E-mails.

To celebrate the triumph of form over content I would also like to add an HTML IMG tag and send a gif as well. The obvious

print MAIL '<IMG SRC="picture.jpg">';

Doesn't work. Anyone know how?

I could lie down like a tired child,
And weep away the life of care
Which I have borne, and yet must bear.
Shelley 1792-1822

Replies are listed 'Best First'.
RE: Picture this
by little (Curate) on Nov 09, 2000 at 16:26 UTC
    As you are sending a URI to a document you have to make sure that the recipient can acces it :-)
    To send images inside a mail the documents MIME type is not "txt/html" but rather "multipart..."
    But I suggest to use Mail::Sender which also allows you to send attachements and ships with examples in it's manpage.
    Have a nice day
    All decision is left to your taste
RE: Picture this
by davorg (Chancellor) on Nov 09, 2000 at 18:14 UTC

    I've just read the article that you describe and it encourages some very bad practices.

    HTML mail should only ever be sent as one part of a multipart MIME message. Another part should have the same message in text/plain. Not everyone will have a mail client which handles HTML emails and a correctly formatted MIME message gives them the chance to read your mail too.

    By all means, send HTML mail if you have to, but use the MIME-Tools bundle of modules from CPAN to format it.

    --
    <http://www.dave.org.uk>

    "Perl makes the fun jobs fun
    and the boring jobs bearable" - me

      Thanks for the advice davorg These mails are on a sub-section of our intranet where everyone has the same mail client installed. I would like to use Mail::Sender but getting admin to install modules can take ages :-(
      Trimbach kindly suggested putting the full URL of the image in the tag. This doesn't work for me as the server requires http authorisation. Pity.

      I could lie down like a tired child,
      And weep away the life of care
      Which I have borne, and yet must bear.
      Shelley 1792-1822
        I strongly advise against this, but it is possible to include the username and password for authentication in the url. Just write the url like an ftp url:
        http://username:password@intranet.company.com/report.html
Re: Picture this
by Trimbach (Curate) on Nov 09, 2000 at 17:33 UTC
    If you want to send an image file as an attachment you can send a multipart message as above, but if all you want to do is include an image in the body of your email all you have to do is use a fully qualified URL for your image. i.e. <img src="http://www.server.com/image.jpg"> instead of <img src="image.jpg">.

    Gary Blackburn
    Trained Killer

Re: Picture this
by cianoz (Friar) on Nov 09, 2000 at 18:47 UTC
    the example below sends the content of a given URL to a given email address
    usage: <programname> <url> <email address>
    #!/usr/bin/perl -w use strict; use MIME::Lite; use MIME::Lite::HTML; my $url = shift; my $to = shift; my $mail = new MIME::Lite::HTML( From => 'you@yourdomain.com', To => $to, Subject => 'your URL'); my $MimeMail = $mail->parse($url); $MimeMail->send_by_smtp('localhost');
      And what to do if you want to generate the content on the fly? This parsing stuff won't help.

      Note: This was not a new idea, or tease, but another question since I am also interested in the topic

      -- tune

        then look at how MIME::Lite::HTML uses MIME::Lite to build the attach...