http://www.perlmonks.org?node_id=136872

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

I want to send an HTML mail with an embedded gif from a Unix box to an NT Outlook client.
So I took the example code from the module Mail::Sender, changed the variables to my local ones and Hey Presto it doesn't work!
It sends the html and gif as attachments to a blank E-mail. The HTML should be the body not another attachment. Surely the example is bugged? Can anyone give a working example?
Thanks in advance
Heres the example copied from the documentation
If you want to send a HTML with some inline images : use strict; use Mail::Sender; my $recipients = 'somebody@somewhere.com'; my $sender = new Mail::Sender {smtp => 'your.mailhost.com'}; if ($sender->OpenMultipart({from => 'itstech2@gate.net', to => $ +recipients, subject => 'Embedded Image Test', subtype +=> 'related', boundary => 'boundary-test-1', type => 'multipart/related'}) > 0) { $sender->SendFile( {description => 'html body', ctype => 'text/html; charset=us-ascii', encoding => '7bit', disposition => 'NONE', file => 'test.html' }); $sender->SendFile( {description => 'ed\'s gif', ctype => 'image/gif', encoding => 'base64', disposition => "inline; filename=\"apache_pb.gif\";\r\nConten +t-ID: <ed1>", file => 'apache_pb.gif' }); $sender->Close() or die "Close failed! $Mail::Sender::Error\n"; } else { die "Cannot send mail: $Mail::Sender::Error\n"; } __END__ In the HTML you'll have this : ... <IMG src="cid:ed1"> ...

Replies are listed 'Best First'.
Re: Mail::Sender problem.
by bjelli (Pilgrim) on Jan 07, 2002 at 22:46 UTC
    <kbd>>Surely the example is bugged? </kbd>

    yes, the NSA routinely installs bugs in the source code of free software.

    sorry, couldn't help myself

    seriously: you didn't cut-and-paste properly, the example you need is in the documentation:

    $sender->OpenMultipart({to => 'Perl-Win32-Users@activeware.foo', subject => 'Mail::Sender.pm - new module'}); $sender->Body; $sender->Send(<<'*END*'); Here is a new module Mail::Sender. It provides an object based interface to sending SMTP mails. It uses a direct socket connection, so it doesn't need any additional program. Enjoy, Jenda *END* $sender->SendFile( {description => 'Perl module Mail::Sender.pm', ctype => 'application/x-zip-encoded', encoding => 'Base64', disposition => 'attachment; filename="Sender.zip"; type="ZIP archive"', file => 'sender.zip' }); $sender->Close;

    And then there's the question whether you should use HTML in the body of an e-mail at all....

    --
    Brigitte    'I never met a chocolate I didnt like'    Jellinek
    http://www.horus.com/~bjelli/         http://perlwelt.horus.at
      The question is similar to one I raised last year. I never did get it working.
      Why HTML in the mail body? Well why not? My users certainly prefer html, it looks a lot more professional than plain ascii. Your example is to add an attachment and is easy to get working. The question, as I understand it, is to use an HTML img tag, send the gif with the mail and have outlook display it properly.

      Management always feel more comfortable if their corporate logos are displayed.

      Update Take out the subtype => 'related', line in the OpenMultipart call and it will work. It just came to me :-)