HTML(3pm) | User Contributed Perl Documentation | HTML(3pm) |
MIME::Lite::HTML - Provide routine to transform a HTML page in a MIME-Lite mail
perl -MMIME::Lite::HTML -e ' new MIME::Lite::HTML From => "MIME-Lite\@alianwebserver.com", To => "alian\@cpan.org", Url => "http://localhost/server-status";'
$Revision: 1.23 $
This module is a Perl mail client interface for sending message that support HTML format and build them for you.. This module provide routine to transform a HTML page in MIME::Lite mail. So you need this module to use MIME-Lite-HTML possibilities
The job done is:
Did you alread see link like "Send this page to a friend" ?. With this module, you can do script that to this in 3 lines.
It can be used too in a HTML newsletter. You make a classic HTML page, and give just url to MIME::Lite::HTML.
MIME-Lite-HTML use a MIME-Lite object, and RFC2557 construction:
If images and text are present, construction use is:
--> multipart/alternative ------> text/plain ------> multipart/related -------------> text/html -------------> each images
If no images but text is present, this is that:
---> multipart/alternative -------> text/plain if present -------> text/html
If images but no text, this is:
---> multipart/related -------> text/html -------> each images
If no images and no text, this is:
---> text/html
Additional documentation can be found here:
HTML in mail is not full supported so this module can't work with all email clients. If some client recognize HTML, they didn't support images include in HTML. So in fact, they recognize multipart/relative but not multipart/related.
With images, Eudora didn't recognize multipart/related part as describe in RFC 2557 even if he can read his own HTML mail. So if images are present in HTML part, text and HTML part will be displayed both, text part in first. Two additional headers will be displayed in HTML part too in this case. Version 1.0 of this module correct major problem of headers displayed with image include in HTML part.
In other case, Kmail didn't support image include in HTML. So if you set in KMail "Prefer HTML to text", it display HTML with images broken. Otherwise, it display text part.
Pegasus didn't support images in HTML. When it find a multipart/related message, it ignore it, and display text part.
If you find others mail client who support (or not support) MIME-Lite-HTML module, give me some feedback ! If you want be sure that your mail can be read by maximum of people, (so not only OE and Netscape), don't include images in your mail, and use a text buffer too. If multipart/related mail is not recognize, multipart/alternative can be read by the most of mail client.
Just do in DOS "shell":
c:\ ppm > set repository alian http://www.alianwebserver.com/perl/CPAN > install MIME-Lite-HTML > quit
Subscribe on http://www.alianwebserver.com/cgi-bin/news_mlh.cgi
The hash can have this key : [Url], [Proxy], [Debug],
[IncludeType],
[HashTemplate], [LoginDetails], [TextCharset], [HTMLCharset],
[TextEncoding], [HTMLEncoding], [remove_jscript]
Eg: Proxy => 'http://192.168.100.166:8080'
Eg: remove_jscript => 1
Eg: Debug => 1
ExternImages => [ '.*cat\.jpg.*', 'external/.*' ]
...would mean that "images/cat.jpg" and "external/foo.jpg" would be sent as external <img> links, but "images/dog.jpg" would be sent using whatever the default IncludeType (above) is.
$hash{'HashTemplate'}{'http://www.al.com/images/sommaire.gif'}=\@data;
or
$hash{'HashTemplate'}{'http://www.al.com/script.js'}="alert("Hello world");;
When module find the image http://www.alianwebserver.com/images/sommaire.gif in buffer, it don't get image with LWP but use data found in $hash{'HashTemplate'}. (See eg/example2.pl)
Eg: LoginDetails => 'my_user:my_password'
Eg: TextCharset => 'iso-8859-7'
for Greek. If none specified, the default is used (iso-8859-1).
Eg: HTMLCharset => 'iso-8859-7'
for Greek. If none specified, the default is used (iso-8859-1). Take care, as that option does NOT change the character set of the HTML page, it only changes the character set of the mime part.
Eg: TextEncoding => 'base64'
Eg: HTMLEncoding => 'base64'.
Others keys are use with MIME::Lite constructor.
This MIME-Lite keys are: Bcc, Encrypted, Received, Sender, Cc, From, References, Subject, Comments, Keywords, Reply-To To, Content-*, Message-ID,Resent-*, X-*,Date, MIME-Version, Return-Path, Organization
Parameters:
http://www.alianwebserver.com file://c|/tmp/index.html <img src=toto.gif>
Return the MIME::Lite part to send
Build the final MIME-Lite object to send with each part read before
See "Construction" in "Description" for know how MIME-Lite object is build.
Fetch if needed $url, and create a MIME part for it.
Search in HTML buffer ($gabarit) to remplace call to extern CSS file with his content. $root is original absolute url where css file will be found.
Search in HTML buffer ($gabarit) to remplace call to extern javascript file with his content. $root is original absolute url where javascript file will be found.
Search in HTML buffer ($gabarit) to remplace input form image with his cid
Return final buffer and list of MIME::Lite part
Replace link to formulaire with absolute link
Give template with remplaced variables Ex: if $$vars{age}=12, and $masque have
J'ai <? $age ?> ans,
this function give:
J'ai 12 ans,
The set_err routine is used privately. You can ask for an array of all the errors which occurred inside the parse routine by calling:
@errors = $mailHTML->errstr;
If no errors where found, it'll return undef.
#!/usr/bin/perl -w # A cgi program that do "Mail this page to a friend"; # Call this script like this : # script.cgi?email=myfriend@isp.com&url=http://www.go.com use strict; use CGI qw/:standard/; use CGI::Carp qw/fatalsToBrowser/; use MIME::Lite::HTML; my $mailHTML = new MIME::Lite::HTML From => 'MIME-Lite@alianwebserver.com', To => param('email'), Subject => 'Your url: '.param('url'); my $MIMEmail = $mailHTML->parse(param('url')); $MIMEmail->send; # or for win user : $mail->send_by_smtp('smtp.fai.com'); print header,"Mail envoye (", param('url'), " to ", param('email'),")<br>\n";
Copyright (c) 2000 by Alain BARBET alian (at) cpan.org
All rights reserved. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
This software comes with NO WARRANTY of any kind. See the COPYING file in the distribution for details.
Alain BARBET alian@cpan.org , see file Changes for helpers.
2021-01-03 | perl v5.32.0 |