1HTML(3)               User Contributed Perl Documentation              HTML(3)
2
3
4

NAME

6       MIME::Lite::HTML - Provide routine to transform a HTML page in a
7       MIME-Lite mail
8

SYNOPSIS

10         perl -MMIME::Lite::HTML -e '
11            new MIME::Lite::HTML
12                From     => "MIME-Lite\@alianwebserver.com",
13                To       => "alian\@cpan.org",
14                Url      => "http://localhost/server-status";'
15

VERSION

17       $Revision: 1.23 $
18

DESCRIPTION

20       This module is a Perl mail client interface for sending message that
21       support HTML format and build them for you..  This module provide
22       routine to transform a HTML page in MIME::Lite mail.  So you need this
23       module to use MIME-Lite-HTML possibilities
24
25   What's happen ?
26       The job done is:
27
28       ·   Get the file (LWP) if needed
29
30       ·   Parse page to find include images (gif, jpg, flash)
31
32       ·   Attach them to mail with adequat header if asked (default)
33
34       ·   Include external CSS,Javascript file
35
36       ·   Replace relative url with absolute one
37
38       ·   Build the final MIME-Lite object with each part found
39
40   Usage
41       Did you alread see link like "Send this page to a friend" ?. With this
42       module, you can do script that to this in 3 lines.
43
44       It can be used too in a HTML newsletter. You make a classic HTML page,
45       and give just url to MIME::Lite::HTML.
46
47   Construction
48       MIME-Lite-HTML use a MIME-Lite object, and RFC2557 construction:
49
50       If images and text are present, construction use is:
51
52         --> multipart/alternative
53         ------> text/plain
54         ------> multipart/related
55         -------------> text/html
56         -------------> each images
57
58       If no images but text is present, this is that:
59
60         ---> multipart/alternative
61         -------> text/plain if present
62         -------> text/html
63
64       If images but no text, this is:
65
66         ---> multipart/related
67         -------> text/html
68         -------> each images
69
70       If no images and no text, this is:
71
72         ---> text/html
73
74   Documentation
75       Additionnal documentation can be found here:
76
77       ·   MIME-lite module
78
79       ·   RFC 822, RFC 1521, RFC 1522 and specially RFC 2557 (MIME
80           Encapsulation of Aggregate Documents, such as HTML)
81
82   Clients tested
83       HTML in mail is not full supported so this module can't work with all
84       email clients. If some client recognize HTML, they didn't support
85       images include in HTML. So in fact, they recognize multipart/relative
86       but not multipart/related.
87
88       Netscape Messager (Linux-Windows)
89           100% ok
90
91       Outlook Express (Windows-Mac)
92           100% ok. Mac work only with Content-Location header. Thx to Steve
93           Benbow for give mr this feedback and for his test.
94
95       Eudora (Windows)
96           If this module just send HTML and text, (without images), 100% ok.
97
98           With images, Eudora didn't recognize multipart/related part as
99           describe in RFC 2557 even if he can read his own HTML mail. So if
100           images are present in HTML part, text and HTML part will be
101           displayed both, text part in first.  Two additional headers will be
102           displayed in HTML part too in this case.  Version 1.0 of this
103           module correct major problem of headers displayed with image
104           include in HTML part.
105
106       KMail (Linux)
107           If this module just send HTML and text, (without images), 100% ok.
108
109           In other case, Kmail didn't support image include in HTML. So if
110           you set in KMail "Prefer HTML to text", it display HTML with images
111           broken. Otherwise, it display text part.
112
113       Pegasus (Windows)
114           If this module just send HTML and text, (without images), 100% ok.
115
116           Pegasus didn't support images in HTML. When it find a
117           multipart/related message, it ignore it, and display text part.
118
119       If you find others mail client who support (or not support) MIME-Lite-
120       HTML module, give me some feedback ! If you want be sure that your mail
121       can be read by maximum of people, (so not only OE and Netscape), don't
122       include images in your mail, and use a text buffer too. If
123       multipart/related mail is not recognize, multipart/alternative can be
124       read by the most of mail client.
125
126   Install on WinX with ActiveState / PPM
127       Just do in DOS "shell":
128
129         c:\ ppm
130         > set repository alian http://www.alianwebserver.com/perl/CPAN
131         > install MIME-Lite-HTML
132         > quit
133
134   How know when next release will be ?
135       Subscribe on http://www.alianwebserver.com/cgi-bin/news_mlh.cgi
136

Public Interface

138       new(%hash)
139           Create a new instance of MIME::Lite::HTML.
140
141           The hash can have this key : [Url], [Proxy], [Debug],
142           [IncludeType],
143            [HashTemplate], [LoginDetails], [TextCharset], [HTMLCharset],
144            [TextEncoding], [HTMLEncoding], [remove_jscript]
145
146           Url ... is url to parse and send. If this param is found, call of
147               parse routine and send of mail is done. Else you must use parse
148               routine of MIME::Lite::HTML and send of MIME::Lite.
149
150           Proxy
151               ... is url of proxy to use.
152
153                 Eg: Proxy => 'http://192.168.100.166:8080'
154
155           remove_jscript
156               if set, remove all script code from html source
157
158                 Eg: remove_jscript => 1
159
160           Debug
161               ... is trace to stdout during parsing.
162
163                 Eg: Debug => 1
164
165           IncludeType
166               ... is method to use when finding images:
167
168               location
169                   Default method is embed them in mail whith
170                   'Content-Location' header.
171
172               cid You use a 'Content-CID' header.
173
174               extern
175                   Images are not embed, relative url are just replace with
176                   absolute, so images are fetch when user read mail. (Server
177                   must be reachable !)
178
179           $hash{'HashTemplate'}
180               ... is a reference to a hash. If present, MIME::Lite::HTML will
181               substitute <? $name ?> with $hash{'HashTemplate'}{'name'} when
182               parse url to send. $hash{'HashTemplate'} can be used too for
183               include data for subelement.  Eg:
184
185                 $hash{'HashTemplate'}{'http://www.al.com/images/sommaire.gif'}=\@data;
186
187               or
188
189                 $hash{'HashTemplate'}{'http://www.al.com/script.js'}="alert("Hello world");;
190
191               When module find the image
192               http://www.alianwebserver.com/images/sommaire.gif in buffer, it
193               don't get image with LWP but use data found in
194               $hash{'HashTemplate'}. (See eg/example2.pl)
195
196           LoginDetails
197               ... is the couple user:password for use with restricted url.
198
199                 Eg: LoginDetails => 'my_user:my_password'
200
201           TextCharset
202               ... is the character set to use for the text part.
203
204                 Eg: TextCharset => 'iso-8859-7'
205
206               for Greek. If none specified, the default is used (iso-8859-1).
207
208           HTMLCharset
209               ... is the character set to use for the html part.
210
211                 Eg:  HTMLCharset => 'iso-8859-7'
212
213               for Greek. If none specified, the default is used (iso-8859-1).
214               Take care, as that option does NOT change the character set of
215               the HTML page, it only changes the character set of the mime
216               part.
217
218           TextEncoding
219               ... is the Encoding to be used for the text part (if such a
220               part exists). If none specified, the default is used (7bit).
221
222                 Eg: TextEncoding => 'base64'
223
224           HTMLEncoding
225               ... is the Encoding to be used for the html part. If none
226               specified, the default is used (quoted-printable).
227
228                 Eg: HTMLEncoding => 'base64'.
229
230           Others keys are use with MIME::Lite constructor.
231
232           This MIME-Lite keys are: Bcc, Encrypted, Received, Sender, Cc,
233           From, References, Subject, Comments, Keywords, Reply-To To,
234           Content-*, Message-ID,Resent-*, X-*,Date, MIME-Version, Return-
235           Path, Organization
236
237       parse($html, [$url_txt], [$url_base])
238           Subroutine used for created HTML mail with MIME-Lite
239
240           Parameters:
241
242           $html
243               Url of HTML file to send, can be a local file. If $url is not
244               an url (http or https or ftp or file or nntp), $url is used as
245               a buffer.  Example :
246
247                 http://www.alianwebserver.com
248                 file://c|/tmp/index.html
249                 <img src=toto.gif>
250
251           $url_txt
252               Url of text part to send for person who doesn't support HTML
253               mail.  As $html, $url_txt can be a simple buffer.
254
255           $url_base
256               $url_base is used if $html is a buffer, for get element found
257               in HTML buffer.
258
259           Return the MIME::Lite part to send
260
261       size()
262           Display size of mail in characters (so octets) that will be send.
263           (So use it *after* parse method). Use this method for control size
264           of mail send, I personnaly hate receive 500k by mail.  I pay for a
265           33k modem :-(
266

Private methods

268       build_mime_object($html,[$txt],[@mail])
269           (private)
270
271           Build the final MIME-Lite object to send with each part read before
272
273           $html
274               Buffer of HTML part
275
276           $txt
277               Buffer of text part
278
279           @mail
280               List of images attached to HTML part. Each item is a MIME-Lite
281               object.
282
283           See "Construction" in "Description" for know how MIME-Lite object
284           is build.
285
286       create_image_part($url)
287           (private)
288
289           Fetch if needed $url, and create a MIME part for it.
290
291       include_css($gabarit,$root)
292           (private)
293
294           Search in HTML buffer ($gabarit) to remplace call to extern CSS
295           file with his content. $root is original absolute url where css
296           file will be found.
297
298       include_javascript($gabarit,$root)
299           (private)
300
301           Search in HTML buffer ($gabarit) to remplace call to extern
302           javascript file with his content. $root is original absolute url
303           where javascript file will be found.
304
305       input_image($gabarit,$root)
306           (private)
307
308           Search in HTML buffer ($gabarit) to remplace input form image with
309           his cid
310
311           Return final buffer and list of MIME::Lite part
312
313       link_form($gabarit,$root)
314           (private)
315
316           Replace link to formulaire with absolute link
317
318       fill_template($masque,$vars)
319           $masque
320               Path of template
321
322           $vars
323               hash ref with keys/val to substitue
324
325           Give template with remplaced variables Ex: if $$vars{age}=12, and
326           $masque have
327
328             J'ai <? $age ?> ans,
329
330           this function give:
331
332             J'ai 12 ans,
333

Error Handling

335       The set_err routine is used privately. You can ask for an array of all
336       the errors which occured inside the parse routine by calling:
337
338       @errors = $mailHTML->errstr;
339
340       If no errors where found, it'll return undef.
341

CGI Example

343         #!/usr/bin/perl -w
344         # A cgi program that do "Mail this page to a friend";
345         # Call this script like this :
346         # script.cgi?email=myfriend@isp.com&url=http://www.go.com
347         use strict;
348         use CGI qw/:standard/;
349         use CGI::Carp qw/fatalsToBrowser/;
350         use MIME::Lite::HTML;
351
352         my $mailHTML = new MIME::Lite::HTML
353            From     => 'MIME-Lite@alianwebserver.com',
354            To       => param('email'),
355            Subject => 'Your url: '.param('url');
356
357         my $MIMEmail = $mailHTML->parse(param('url'));
358         $MIMEmail->send; # or for win user : $mail->send_by_smtp('smtp.fai.com');
359         print header,"Mail envoye (", param('url'), " to ", param('email'),")<br>\n";
360

TERMS AND CONDITIONS

362         Copyright (c) 2000 by Alain BARBET alian (at) cpan.org
363
364       All rights reserved.  This program is free software; you can
365       redistribute it and/or modify it under the same terms as Perl itself.
366
367       This software comes with NO WARRANTY of any kind.  See the COPYING file
368       in the distribution for details.
369

AUTHOR

371       Alain BARBET alian@cpan.org , see file Changes for helpers.
372
373
374
375perl v5.12.3                      2008-10-14                           HTML(3)
Impressum