NAME
MIME::Lite::HTML - Provide routine to transform a HTML page in a MIME-Lite mail
SYNOPSIS
use MIME::Lite;
use MIME::Lite::HTML;
my $mailHTML = new MIME::Lite::HTML
From => 'MIME-Lite@alianwebserver.com',
To => 'alian@jupiter',
Subject => 'Mail in HTML with images';
$MIMEmail = $mailHTML->parse('http://www.alianwebserver.com');
$MIMEmail->send; # or for win user : $mail->send_by_smtp('smtp.fai.com');
DESCRIPTION
This module provide routine to transform a HTML page in MIME::Lite mail. So you need this module to use MIME-Lite-HTML possibilities
What's happen ?
The job done is:
Get the file (LWP) if needed
Parse page to find include images
Attach them to mail with adequat cid
Include external CSS,Javascript file
Replace relative url with absolute one
Usage
It can be used by example in a HTML newsletter. You make a classic HTML page, and give just url to MIME::Lite::HTML.
Construction
MIME-Lite-HTML use a MIME-Lite object, build with
--> multipart/alternative
------> text/plain if present
------> multipart/related
-------------> text/html
-------------> each images
Documentation
Additionnal documentation can be found here:
MIME-lite module
RFC 822, RFC 1521, RFC 1522 and specially RFC 2257 (MIME Encapsulation of Aggregate Documents, such as HTML)
Clients tested
HTML in mail is not a standart, so this module can't work with all mail clients.
Clients who has been tested:
Outlook Express : 100% ok
Netscape Messager : 100% ok
Eudora : Two problems : Two additional headers will be displayed in HTML part and Eudora didn't recognize multipart/alternative part as describe in RFC 2257 so text and HTML part will be displayed both, text part in first. Version 1.0 of this module correct major problem of headers with image include in HTML part. May be a solution is not use mail text with MIME-Lite-HTML, and use MIME-Lite for text mail. Ask your users what they want ...
VERSION
$Revision: 1.1 $
METHODS
new(%hash)
Create a new instance of MIME::Lite::HTML.
%hash can have this key : [Proxy], [Debug], [HashTemplate] 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
$hash{'HashTemplate'} is a reference to a hash. If present, MIME::Lite::HTML will substitute <? $name ?> with $hash{'HashTemplate'}{'name'} when parse url to send. $hash{'HashTemplate'} can be used too for include data for subelement. Ex: $hash{'HashTemplate'}{'http://www.alianwebserver.com/images/sommaire.gif'}=\@data; or $hash{'HashTemplate'}{'http://www.alianwebserver.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'}.
parse($html, [$url_txt], [$url_base])
Subroutine used for created HTML mail with MIME-Lite
Parameters:
- $html
-
Url of HTML file to send, can be a local file. If $url is not an url (http or https or ftp or file or nntp), $url is used as a buffer. Example : http://www.alianwebserver.com, file://c|/tmp/index.html or '<img src=toto.gif>'.
- $url_txt
-
Url of text part to send for person who doesn't support HTML mail. As $html, $url_txt can be a simple buffer.
- $url_base
-
$url_base is used if $html is a buffer, for get element found in HTML buffer.
Return the MIME::Lite part to send
Private methods
include_css($gabarit,$root)
(private)
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.
include_javascript($gabarit,$root)
(private)
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.
input_image($gabarit,$root)
(private)
Search in HTML buffer ($gabarit) to remplace input form image with his cid
Return final buffer and list of MIME::Lite part
link_form($gabarit,$root)
(private)
Replace link to formulaire with absolute link
fill_template($masque,$vars)
$masque : Path of template
$vars : hash ref with keys/val to substitue
Give template with remplaced variables Ex: if $$vars{age}=12, and $masque have
J'ai <? $age ?> ans,
this function give:
J'ai 12 ans,
Error Handling
The set_err routine is used privately. You can ask for an array of all the errors which occured inside the parse routine by calling:
@errors = $mailHTML->errstr;
If no errors where found, it'll return undef.
AUTHOR
Alain BARBET alian@alianwebserver.com