Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

HTML email with attachments

by Anonymous Monk
on Aug 03, 2005 at 04:14 UTC ( [id://480355]=perlquestion: print w/replies, xml ) Need Help??

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

Hi perl monks, I'm trying to write a program to handle sending email. I am using Mime::Lite. I am wanting to use embedded images in the HTML document. I can attach the files no problem, but can not display them in the body of the email. Heres the code.
$msg = MIME::Lite->new ( To =>'someone@somewhere.co.nz', From => 'mail@someone.co.nz', Subject =>'mailbird', Type =>'multipart/mixed', ); $msg->attach(Type => 'text/html', Data => qq~ <html> <body bgcolor="red"> <img src="http://www.google.co.nz/images/hp0.gif" alt="Google L +OGO"> <p><font size=4>Taieri Print Ltd</font></p> <img src="tplogo.jpg" alt="TP LOGO"> <p><font size=2 color="blue">Mailbird Newsletter</font></p> </body> </html> ~); $msg->attach(Type =>'image/jpg', Path =>'tplogo.jpg', Filename =>'logo.jpg', disposition=>'inline', ); $msg->send('smtp', 'smtp.xtra.co.nz') or die 'Message not sent to $rec +ipient';
When i reference a image located on a web server it works, but with later version of email clients such as Mozilla and Outlook, it requires the user to click on a button to display the image. This step is not wanted. Any ideas or guidance would be appreciated. Thanks

Replies are listed 'Best First'.
Re: HTML email with attachments
by ikegami (Patriarch) on Aug 03, 2005 at 05:05 UTC

    The docs provide an example on how to do this:

    $msg = MIME::Lite->new( To =>'you@yourhost.com', 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();

    Notice the URL is cid: followed by the value specified in the image's Id field.

Re: HTML email with attachments
by merlyn (Sage) on Aug 03, 2005 at 06:50 UTC
A reply falls below the community's threshold of quality. You may see it by logging in.

Log In?
Username:
Password:

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

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

    No recent polls found