Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

Re: Sending Inline Images in e-mail with Mail::Sender (or getting them to print in Outlook)

by bbfu (Curate)
on Mar 04, 2003 at 03:11 UTC ( [id://240223]=note: print w/replies, xml ) Need Help??


in reply to Sending Inline Images in e-mail with Mail::Sender (or getting them to print in Outlook)

Well, a couple minor things. Firstly, you didn't include the HTML file you use (file.html), which can make a difference. The problem might lie there. Specifically, with the syntax of the src="cid:img" references.

Also, you're manually embedding one header (Content-ID) within another. It should work the way you have it, but it is "more correct" to use the content_id parameter to Attach (see code below).

And though I'm sure it doesn't make any difference to the problem, you're giving the wrong content-type for the jpeg ('image/gif' instead of 'image/jpeg').

Here is your code, slightly modified and formatted, and the html file I used. It seems to work for me, though I don't actually have Outlook to test it with. As far as I can tell, this is "correct", though, so it should work the same with Outlook as with my email client (PocoMail). If this doesn't work with Outlook, then I can only assume the problem is with Outlook and printing inline images. Perhaps you could try it in another mail client to see if it's an Outlook-specific issue.

Update: There is a Knowledge Base Article (#287768) about this issue. You should check that to see if it's the same problem.

The code:

#!/usr/bin/perl use warnings; use strict; use Mail::Sender; my $sender = new Mail::Sender {smtp => 'your-smtp-server', from => 'testing@example.com'}; if (ref $sender->OpenMultipart({ from => 'testing@example.com', to => $to, subject => 'mail message', boundary => 'boundary-test-1', multipart => 'related', })) { print "Attaching body...\n"; $sender->Attach({ description => 'html body', ctype => 'text/html; charset=us-ascii', encoding => '7bit', disposition => 'none', file => 'file.html', }); print "Attaching jpeg...\n"; $sender->Attach({ description => 'file1.jpg', ctype => 'image/jpeg', encoding => 'base64', disposition => 'inline; filename="file1.jpg";', content_id => 'img1', file => 'file1.jpg' }); print "Attaching gif...\n"; $sender->Attach({ description => 'logo.gif', ctype => 'image/gif', encoding => 'base64', disposition => 'inline; filename="logo.gif";', content_id => 'img2', file => 'logo.gif' }); print "Closing / Sending\n"; $sender->Close() or die "Close failed! $Mail::Sender::Error\n"; } else { die "Cannot send mail: $Mail::Sender::Error\n"; }

The file.html:

<html> <body> <p>Inline image number 1 (jpeg): <img src="cid:img1"> <p>Inline image number 2 (gif): <img src="cid:img2"> </body> </html>

bbfu
Black flowers blossum
Fearless on my breath

Replies are listed 'Best First'.
Re^2: Sending Inline Images in e-mail with Mail::Sender (or getting them to print in Outlook)
by zaffa (Initiate) on Nov 24, 2007 at 00:24 UTC
    i was trying the same thing, and typed your code in and i can't get any of the images in the outlook email. they seem to be files, in the body of the email. in ms express they show up fine. is there a setting in Outlook that i should set? thanks in advance!

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://240223]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others admiring the Monastery: (6)
As of 2024-03-29 13:01 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found