<HTML>
<HEAD>
<TITLE>MIME::Lite</TITLE>
</HEAD>
<BODY
bgcolor="#FFFFFF" link="#BE1B58" vlink="#8C337C" alink="#F28EAA">
<A HREF="http://www.zeegee.com" TARGET="_top"><IMG SRC="icons/zeegee.gif" ALT="ZeeGee Software" ALIGN="RIGHT" BORDER="0"></A><A NAME="__TOP__"><H1>MIME::Lite</H1>
</A><UL>
<LI> <A HREF="#NAME">NAME</A>
<LI> <A HREF="#SYNOPSIS">SYNOPSIS</A>
<LI> <A HREF="#DESCRIPTION">DESCRIPTION</A>
<LI> <A HREF="#MORE_EXAMPLES">MORE EXAMPLES</A>
<UL>
<LI> <A HREF="#Attach_a_GIF_to_a_text_message">Attach a GIF to a text message</A>
<LI> <A HREF="#Send_an_HTML_document_with_images_included">Send an HTML document... with images included!</A>
<LI> <A HREF="#Output_a_message_to_a_filehandle">Output a message to a filehandle</A>
<LI> <A HREF="#Get_a_message_as_a_string">Get a message as a string</A>
<LI> <A HREF="#Change_how_messages_are_sent">Change how messages are sent</A>
</UL>
<LI> <A HREF="#PUBLIC_INTERFACE">PUBLIC INTERFACE</A>
<UL>
<LI> <A HREF="#Construction">Construction</A>
<LI> <A HREF="#Setting_getting_headers_and_attributes">Setting/getting headers and attributes</A>
<LI> <A HREF="#Setting_getting_message_data">Setting/getting message data</A>
<LI> <A HREF="#Output">Output</A>
<LI> <A HREF="#Sending">Sending</A>
<LI> <A HREF="#Miscellaneous">Miscellaneous</A>
</UL>
<LI> <A HREF="#NOTES">NOTES</A>
<UL>
<LI> <A HREF="#Limitations">Limitations</A>
<LI> <A HREF="#Cheap_and_easy_mailing">Cheap and easy mailing</A>
<LI> <A HREF="#Under_the_hood">Under the hood</A>
</UL>
<LI> <A HREF="#WARNINGS">WARNINGS</A>
<UL>
<LI> <A HREF="#MIME-_and_non-MIME_header_fields">MIME- and non-MIME header fields</A>
<LI> <A HREF="#Lines_consisting_of_a_single_dot">Lines consisting of a single dot</A>
</UL>
<LI> <A HREF="#A_MIME_PRIMER">A MIME PRIMER</A>
<UL>
<LI> <A HREF="#Content_types">Content types</A>
<LI> <A HREF="#Content_transfer_encodings">Content transfer encodings</A>
</UL>
<LI> <A HREF="#CHANGE_LOG">CHANGE LOG</A>
<LI> <A HREF="#TERMS_AND_CONDITIONS">TERMS AND CONDITIONS</A>
<LI> <A HREF="#NUTRITIONAL_INFORMATION">NUTRITIONAL INFORMATION</A>
<LI> <A HREF="#AUTHOR">AUTHOR</A>
</UL>
</A>
<P><HR>
<A NAME="NAME"><H2><A HREF="#__TOP__"><IMG SRC="icons/h1bullet.gif" ALT="Top" BORDER="0"></A> NAME</H2></A>
<P>MIME::Lite - low-calorie MIME generator
<P><HR>
<A NAME="SYNOPSIS"><H2><A HREF="#__TOP__"><IMG SRC="icons/h1bullet.gif" ALT="Top" BORDER="0"></A> SYNOPSIS</H2></A>
<PRE>
use MIME::Lite;
Create a single-part message:
</PRE>
<PRE>
### Create a new single-part message, to send a GIF file:
$msg = MIME::Lite->new(
From =>'me@myhost.com',
To =>'you@yourhost.com',
Cc =>'some@other.com, some@more.com',
Subject =>'Helloooooo, nurse!',
Type =>'image/gif',
Encoding =>'base64',
Path =>'hellonurse.gif'
);
</PRE>
<P>Create a multipart message (i.e., one with attachments):
<PRE>
### Create a new multipart message:
$msg = MIME::Lite->new(
From =>'me@myhost.com',
To =>'you@yourhost.com',
Cc =>'some@other.com, some@more.com',
Subject =>'A message with 2 parts...',
Type =>'multipart/mixed'
);
### Add parts (each "attach" has same arguments as "new"):
$msg->attach(Type =>'TEXT',
Data =>"Here's the GIF file you wanted"
);
$msg->attach(Type =>'image/gif',
Path =>'aaa000123.gif',
Filename =>'logo.gif'
);
</PRE>
<P>Output a message:
<PRE>
# Format as a string:
$str = $msg->as_string;
# Print to a filehandle (say, a "sendmail" stream):
$msg->print(\*SENDMAIL);
</PRE>
<P>Send a message:
<PRE>
# Send in the "best" way (the default is to use "sendmail"):
$msg->send;
</PRE>
<P><HR>
<A NAME="DESCRIPTION"><H2><A HREF="#__TOP__"><IMG SRC="icons/h1bullet.gif" ALT="Top" BORDER="0"></A> DESCRIPTION</H2></A>
<P>In the never-ending quest for great taste with fewer calories,
we proudly present: <I>MIME::Lite</I>.
<P>MIME::Lite is intended as a simple, standalone module for generating
(not parsing!) MIME messages... specifically, it allows you to
output a simple, decent single- or multi-part message with text or binary
attachments. It does not require that you have the Mail:: or MIME::
modules installed.
<P>You can specify each message part as either the literal data itself (in
a scalar or array), or as a string which can be given to open() to get
a readable filehandle (e.g., "<filename" or "somecommand|").
<P>You don't need to worry about encoding your message data:
this module will do that for you. It handles the 5 standard MIME encodings.
<P>If you need more sophisticated behavior, please get the MIME-tools
package instead. I will be more likely to add stuff to that toolkit
over this one.
<P><HR>
<A NAME="MORE_EXAMPLES"><H2><A HREF="#__TOP__"><IMG SRC="icons/h1bullet.gif" ALT="Top" BORDER="0"></A> MORE EXAMPLES</H2></A>
<P><HR>
<A NAME="Attach_a_GIF_to_a_text_message"><H3><A HREF="#__TOP__"><IMG SRC="icons/h2bullet.gif" ALT="Top" BORDER="0"></A> Attach a GIF to a text message</H3></A>
<P>This will create a multipart message exactly as above, but using the
"attach to singlepart" hack:
<PRE>
### Create a new multipart message:
$msg = MIME::Lite->new(
From =>'me@myhost.com',
To =>'you@yourhost.com',
Cc =>'some@other.com, some@more.com',
Subject =>'A message with 2 parts...',
Type =>'TEXT',
Data =>"Here's the GIF file you wanted"
);
### Attach a part:
$msg->attach(Type =>'image/gif',
Path =>'aaa000123.gif',
Filename =>'logo.gif'
);
</PRE>
<P><HR>
<A NAME="Send_an_HTML_document_with_images_included"><H3><A HREF="#__TOP__"><IMG SRC="icons/h2bullet.gif" ALT="Top" BORDER="0"></A> Send an HTML document... with images included!</H3></A>
<PRE>
$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();
</PRE>
<P><HR>
<A NAME="Output_a_message_to_a_filehandle"><H3><A HREF="#__TOP__"><IMG SRC="icons/h2bullet.gif" ALT="Top" BORDER="0"></A> Output a message to a filehandle</H3></A>
<PRE>
### Write it to a filehandle:
$msg->print(\*STDOUT);
### Write just the header:
$msg->print_header(\*STDOUT);
### Write just the encoded body:
$msg->print_body(\*STDOUT);
</PRE>
<P><HR>
<A NAME="Get_a_message_as_a_string"><H3><A HREF="#__TOP__"><IMG SRC="icons/h2bullet.gif" ALT="Top" BORDER="0"></A> Get a message as a string</H3></A>
<PRE>
### Get entire message as a string:
$str = $msg->as_string;
### Get just the header:
$str = $msg->header_as_string;
### Get just the encoded body:
$str = $msg->body_as_string;
</PRE>
<P><HR>
<A NAME="Change_how_messages_are_sent"><H3><A HREF="#__TOP__"><IMG SRC="icons/h2bullet.gif" ALT="Top" BORDER="0"></A> Change how messages are sent</H3></A>
<PRE>
### Do something like this in your 'main':
if ($I_DONT_HAVE_SENDMAIL) {
MIME::Lite->send('smtp', "smtp.myisp.net", Timeout=>60);
}
### Now this will do the right thing:
$msg->send; ### will now use Net::SMTP as shown above
</PRE>
<P><HR>
<A NAME="PUBLIC_INTERFACE"><H2><A HREF="#__TOP__"><IMG SRC="icons/h1bullet.gif" ALT="Top" BORDER="0"></A> PUBLIC INTERFACE</H2></A>
<P><HR>
<A NAME="Construction"><H3><A HREF="#__TOP__"><IMG SRC="icons/h2bullet.gif" ALT="Top" BORDER="0"></A> Construction</H3></A>
<DL>
<P><DT><B><A NAME="item:new">new [PARAMHASH]</A></B></DT>
<DD>
<I>Class method, constructor.</I>
Create a new message object.
<P>If any arguments are given, they are passed into <CODE>build()</CODE>; otherwise,
just the empty object is created.
<P><DT><B><A NAME="item:attach">attach [OBJECT|PARAMHASH]</A></B></DT>
<DD>
<I>Instance method.</I>
Add a new part to this message, and return the new part.
<P>You can attach a MIME::Lite OBJECT, or have it create one by specifying
a PARAMHASH that will be automatically given to <CODE>new()</CODE>.
<P>One of the possibly-quite-useful hacks thrown into this is the
"attach-to-singlepart" hack: if you attempt to attach a part (let's
call it "part 1") to a message that <I>isn't</I> a multipart message
(the "self" object in this case), the following happens:
<UL>
<P><LI>
<P>A new part (call it "part 0") is made.
<P><LI>
<P>The MIME attributes and data (but <I>not</I> the other headers)
are cut from the "self" message, and pasted into "part 0".
<P><LI>
<P>The "self" is turned into a "multipart/mixed" message.
<P><LI>
<P>The new "part 0" is added to the "self", and <I>then</I> "part 1" is added.
</UL>
<P>One of the nice side-effects is that you can create a text message
and then add zero or more attachments to it, much in the same way
that a user agent like Netscape allows you to do.
<P><DT><B><A NAME="item:build">build [PARAMHASH]</A></B></DT>
<DD>
<I>Class/instance method, initiallizer.</I>
Create (or initiallize) a MIME message object.
Normally, you'll use the following keys in PARAMHASH:
<PRE>
* Data, FH, or Path (either one of these, or none if multipart)
* Type (e.g., "image/jpeg")
* From, To, and Subject (if this is the "top level" of a message)
</PRE>
<P>The PARAMHASH can contain the following keys:
<DL>
<P><DT><B><A NAME="item:fieldname">(fieldname)</A></B></DT>
<DD>
Any field you want placed in the message header, taken from the
standard list of header fields (you don't need to worry about case):
<PRE>
Bcc Encrypted Received Sender
Cc From References Subject
Comments Keywords Reply-To To
Content-* Message-ID Resent-* X-*
Date MIME-Version Return-Path
Organization
</PRE>
<P>To give experienced users some veto power, these fields will be set
<I>after</I> the ones I set... so be careful: <I>don't set any MIME fields</I>
(like <CODE>Content-type</CODE>) unless you know what you're doing!
<P>To specify a fieldname that's <I>not</I> in the above list, even one that's
identical to an option below, just give it with a trailing <CODE>":"</CODE>,
like <CODE>"My-field:"</CODE>. When in doubt, that <I>always</I> signals a mail
field (and it sort of looks like one too).
<P><DT><B><A NAME="item:Data">Data</A></B></DT>
<DD>
<I>Alternative to "Path" or "FH".</I>
The actual message data. This may be a scalar or a ref to an array of
strings; if the latter, the message consists of a simple concatenation
of all the strings in the array.
<P><DT><B><A NAME="item:Disposition">Disposition</A></B></DT>
<DD>
<I>Optional.</I>
The content disposition, <CODE>"inline"</CODE> or <CODE>"attachment"</CODE>.
The default is <CODE>"inline"</CODE>.
<P><DT><B><A NAME="item:Encoding">Encoding</A></B></DT>
<DD>
<I>Optional.</I>
The content transfer encoding that should be used to encode your data:
<PRE>
Use encoding: If your message contains:
------------------------------------------------------------
7bit Only 7-bit text, all lines <1000 characters
8bit 8-bit text, all lines <1000 characters
quoted-printable 8-bit text or long lines (MUCH more reliable than "8bit")
base64 Largely non-textual data: a GIF, a tar file, etc.
</PRE>
<P>The default is taken from the Type; generally it is "binary" (no
encoding) for text/*, message/*, and multipart/*, and "base64" for
everything else. A value of <CODE>"binary"</CODE> is generally <I>not</I> suitable
for sending anything but ASCII text files with lines under 1000
characters, so consider using one of the other values instead.
<P>In the case of "7bit"/"8bit", long lines are automatically chopped to
legal length; in the case of "7bit", all 8-bit characters are
automatically <I>removed</I>. This may not be what you want, so pick your
encoding well! For more info, see <A HREF="#A_MIME_PRIMER">A MIME PRIMER</A>.
<P><DT><B><A NAME="item:FH">FH</A></B></DT>
<DD>
<I>Alternative to "Data" or "Path".</I>
Filehandle containing the data, opened for reading.
See "ReadNow" also.
<P><DT><B><A NAME="item:Filename">Filename</A></B></DT>
<DD>
<I>Optional.</I>
The name of the attachment. You can use this to supply a filename
if the one in the Path is inadequate, or if you're using the Data argument.
<P>=item Id
<I>Optional.</I>
Same as setting "content-id".
<P><DT><B><A NAME="item:Length">Length</A></B></DT>
<DD>
<I>Optional.</I>
Set the content length explicitly. Normally, this header is automatically
computed, but only under certain circumstances (see <A HREF="#Limitations">Limitations</A>).
<P><DT><B><A NAME="item:Path">Path</A></B></DT>
<DD>
<I>Alternative to "Data" or "FH".</I>
Path to a file containing the data... actually, it can be any open()able
expression. If it looks like a path, the last element will automatically
be treated as the filename.
See "ReadNow" also.
<P><DT><B><A NAME="item:ReadNow">ReadNow</A></B></DT>
<DD>
<I>Optional, for use with "Path".</I>
If true, will open the path and slurp the contents into core now.
This is useful if the Path points to a command and you don't want
to run the command over and over if outputting the message several
times. <B>Fatal exception</B> raised if the open fails.
<P><DT><B><A NAME="item:Top">Top</A></B></DT>
<DD>
<I>Optional.</I>
If defined, indicates whether or not this is a "top-level" MIME message.
The parts of a multipart message are <I>not</I> top-level.
Default is true.
<P><DT><B><A NAME="item:Type">Type</A></B></DT>
<DD>
<I>Optional.</I>
The MIME content type, or one of these special values (case-sensitive):
<PRE>
"TEXT" means "text/plain"
"BINARY" means "application/octet-stream"
</PRE>
<P>The default is <CODE>"TEXT"</CODE>.
</DL>
<P>A picture being worth 1000 words (which
is of course 2000 bytes, so it's probably more of an "icon" than a "picture",
but I digress...), here are some examples:
<PRE>
$msg = build MIME::Lite
From => 'yelling@inter.com',
To => 'stocking@fish.net',
Subject => "Hi there!",
Type => 'TEXT',
Encoding => '7bit',
Data => "Just a quick note to say hi!";
$msg = build MIME::Lite
From => 'dorothy@emerald-city.oz',
To => 'gesundheit@edu.edu.edu',
Subject => "A gif for U"
Type => 'image/gif',
Path => "/home/httpd/logo.gif";
$msg = build MIME::Lite
From => 'laughing@all.of.us',
To => 'scarlett@fiddle.dee.de',
Subject => "A gzipp'ed tar file",
Type => 'x-gzip',
Path => "gzip < /usr/inc/somefile.tar |",
ReadNow => 1,
Filename => "somefile.tgz";
</PRE>
<P>To show you what's really going on, that last example could also
have been written:
<PRE>
$msg = new MIME::Lite;
$msg->build(Type => 'x-gzip',
Path => "gzip < /usr/inc/somefile.tar |",
ReadNow => 1,
Filename => "somefile.tgz");
$msg->add(From => "laughing@all.of.us");
$msg->add(To => "scarlett@fiddle.dee.de");
$msg->add(Subject => "A gzipp'ed tar file");
</PRE>
</DL>
<P><HR>
<A NAME="Setting_getting_headers_and_attributes"><H3><A HREF="#__TOP__"><IMG SRC="icons/h2bullet.gif" ALT="Top" BORDER="0"></A> Setting/getting headers and attributes</H3></A>
<DL>
<P><DT><B><A NAME="item:add">add TAG,VALUE</A></B></DT>
<DD>
Add field TAG with the given VALUE to the end of the header.
The TAG will be converted to all-lowercase, and the VALUE
will be made "safe" (returns will be given a trailing space).
<P><B>Beware:</B> any MIME fields you "add" will override any MIME
attributes I have when it comes time to output those fields.
Normally, you will use this method to add <I>non-MIME</I> fields:
<PRE>
$msg->add("Subject" => "Hi there!");
</PRE>
<P>Giving VALUE an arrayref will cause all those values to be added:
<PRE>
$msg->add("Received" => ["here", "there", "everywhere"]
</PRE>
<P><I>Note:</I> add() is probably going to be more efficient than <CODE>replace()</CODE>,
so you're better off using it for most applications.
<P><I>Note:</I> the name comes from Mail::Header.
<P><DT><B><A NAME="item:attr">attr ATTR,[VALUE]</A></B></DT>
<DD>
Set MIME attribute ATTR to the string VALUE.
ATTR is converted to all-lowercase.
This method is normally used to set/get MIME attributes:
<PRE>
$msg->attr("content-type" => "text/html");
$msg->attr("content-type.charset" => "US-ASCII");
$msg->attr("content-type.name" => "homepage.html");
</PRE>
<P>This would cause the final output to look something like this:
<PRE>
Content-type: text/html; charset=US-ASCII; name="homepage.html"
</PRE>
<P>Note that the special empty sub-field tag indicates the anonymous
first sub-field.
<P>Giving VALUE as undefined will cause the contents of the named
subfield to be deleted.
<P>Supplying no VALUE argument just returns the attribute's value:
<PRE>
$type = $msg->attr("content-type"); # returns "text/html"
$name = $msg->attr("content-type.name"); # returns "homepage.html"
</PRE>
<P><DT><B><A NAME="item:delete">delete TAG</A></B></DT>
<DD>
Delete field TAG with the given VALUE to the end of the header.
The TAG will be converted to all-lowercase.
<PRE>
$msg->delete("Subject");
</PRE>
<P><I>Note:</I> the name comes from Mail::Header.
<P><DT><B><A NAME="item:fields">fields</A></B></DT>
<DD>
Return the full header for the object, as a ref to an array
of <CODE>[TAG, VALUE]</CODE> pairs.
<P>Any fields that the user has explicitly set will override the
corresponding MIME fields that we would generate. So: <I>don't</I> say:
<PRE>
$msg->set("Content-type" => "text/html; charset=US-ASCII");
</PRE>
<P>unless you <I>mean it</I>!
<P><I>Note:</I> I called this "fields" because the header() method of
Mail::Header returns something different, but similar enough to
be confusing.
<P><DT><B><A NAME="item:filename">filename [FILENAME]</A></B></DT>
<DD>
Set the filename which this data will be reported as.
This actually sets both "standard" attributes.
<P>With no argument, returns the filename as dictated by the
content-disposition.
<P><DT><B><A NAME="item:get">get TAG,[INDEX]</A></B></DT>
<DD>
Get the contents of field TAG, which might have been set
with set() or replace(). Returns the text of the field.
<PRE>
$ml->get('Subject', 0);
</PRE>
<P>If the optional 0-based INDEX is given, then we return the INDEX'th
occurence of field TAG. Otherwise, we look at the context:
In a scalar context, only the first (0th) occurence of the
field is returned; in an array context, <I>all</I> occurences are returned.
<P><I>Warning:</I> this should only be used with non-MIME fields.
Behavior with MIME fields is TBD, and will raise an exception for now.
<P><DT><B><A NAME="item:get_length">get_length</A></B></DT>
<DD>
Recompute the content length for the message <I>if the process is trivial</I>,
setting the "content-length" attribute as a side-effect:
<PRE>
$msg->get_length;
</PRE>
<P>Returns the length, or undefined if not set.
<P><I>Note:</I> the content length can be difficult to compute, since it
involves assembling the entire encoded body and taking the length
of it (which, in the case of multipart messages, means freezing
all the sub-parts, etc.).
<P>This method only sets the content length to a defined value if the
message is a singlepart with <CODE>"binary"</CODE> encoding, <I>and</I> the body is
available either in-core or as a simple file. Otherwise, the content
length is set to the undefined value.
<P>Since content-length is not a standard MIME field anyway (that's right, kids:
it's not in the MIME RFCs, it's an HTTP thing), this seems pretty fair.
<P><DT><B><A NAME="item:replace">replace TAG,VALUE</A></B></DT>
<DD>
Delete all occurences of fields named TAG, and add a new
field with the given VALUE. TAG is converted to all-lowercase.
<P><B>Beware:</B> any MIME fields you "replace" will override any MIME
attributes I have when it comes time to output those fields.
Normally, you will use this method to set <I>non-MIME</I> fields:
<PRE>
$msg->replace("Subject" => "Hi there!");
</PRE>
<P>Giving VALUE as undefined will simply cause the contents of the named
field to be deleted. Giving VALUE as an arrayref will cause all the values
in the array to be added.
<P><I>Note:</I> the name comes from Mail::Header.
</DL>
<P><HR>
<A NAME="Setting_getting_message_data"><H3><A HREF="#__TOP__"><IMG SRC="icons/h2bullet.gif" ALT="Top" BORDER="0"></A> Setting/getting message data</H3></A>
<DL>
<P><DT><B><A NAME="item:binmode">binmode [OVERRIDE]</A></B></DT>
<DD>
With no argument, returns whether or not it thinks that the data
(as given by the "Path" argument of <CODE>build()</CODE>) should be read using
binmode() (for example, when <CODE>read_now()</CODE> is invoked).
<P>The default behavior is that any content type other than
<CODE>text/*</CODE> or <CODE>message/*</CODE> is binmode'd; this should in general work fine.
<P>With a defined argument, this method sets an explicit "override"
value. An undefined argument unsets the override.
The new current value is returned.
<P><DT><B><A NAME="item:data">data [DATA]</A></B></DT>
<DD>
Get/set the literal DATA of the message. The DATA may be
either a scalar, or a reference to an array of scalars (which
will simply be joined).
<P><I>Warning:</I> setting the data causes the "content-length" attribute
to be recomputed (possibly to nothing).
<P><DT><B><A NAME="item:path">path [PATH]</A></B></DT>
<DD>
Get/set the PATH to the message data.
<P><I>Warning:</I> setting the path recomputes any existing "content-length" field,
and re-sets the "filename" (to the last element of the path if it
looks like a simple path, and to nothing if not).
<P><DT><B><A NAME="item:fh">fh [FILEHANDLE]</A></B></DT>
<DD>
Get/set the FILEHANDLE which contains the message data.
<P>Takes a filehandle as an input and stores it in the object.
This routine is similar to path(); one important difference is that
no attempt is made to set the content length.
<P><DT><B><A NAME="item:resetfh">resetfh [FILEHANDLE]</A></B></DT>
<DD>
Set the current position of the filehandle back to the beginning.
Only applies if you used "FH" in build() or attach() for this message.
<P>Returns false if unable to reset the filehandle (since not all filehandles
are seekable).
<P><DT><B><A NAME="item:read_now">read_now</A></B></DT>
<DD>
Forces data from the path/filehandle (as specified by <CODE>build()</CODE>)
to be read into core immediately, just as though you had given it
literally with the <CODE>Data</CODE> keyword.
<P>Note that the in-core data will always be used if available.
<P>Be aware that everything is slurped into a giant scalar: you may not want
to use this if sending tar files! The benefit of <I>not</I> reading in the data
is that very large files can be handled by this module if left on disk
until the message is output via <CODE>print()</CODE> or <CODE>print_body()</CODE>.
<P><DT><B><A NAME="item:sign">sign PARAMHASH</A></B></DT>
<DD>
Sign the message. This forces the message to be read into core,
after which the signature is appended to it.
<DL>
<P><DT><B><A NAME="item:Data">Data</A></B></DT>
<DD>
As in <CODE>build()</CODE>: the literal signature data.
Can be either a scalar or a ref to an array of scalars.
<P><DT><B><A NAME="item:Path">Path</A></B></DT>
<DD>
As in <CODE>build()</CODE>: the path to the file.
</DL>
<P>If no arguments are given, the default is:
<PRE>
Path => "$ENV{HOME}/.signature"
</PRE>
<P>The content-length is recomputed.
<P><DT><B><A NAME="item:verify_data">verify_data</A></B></DT>
<DD>
<I>Instance method.</I>
Verify that all "paths" to attached data exist, recursively.
It might be a good idea for you to do this before a print(), to
prevent accidental partial output if a file might be missing.
Raises exception if any path is not readable.
</DL>
<P><HR>
<A NAME="Output"><H3><A HREF="#__TOP__"><IMG SRC="icons/h2bullet.gif" ALT="Top" BORDER="0"></A> Output</H3></A>
<DL>
<P><DT><B><A NAME="item:print">print [OUTHANDLE]</A></B></DT>
<DD>
<I>Instance method.</I>
Print the message to the given output handle, or to the currently-selected
filehandle if none was given.
<P>All OUTHANDLE has to be is a filehandle (possibly a glob ref), or
any object that responds to a print() message.
<P><DT><B><A NAME="item:print_body">print_body [OUTHANDLE]</A></B></DT>
<DD>
<I>Instance method.</I>
Print the body of the message to the given output handle,
or to the currently-selected filehandle if none was given.
<P>All OUTHANDLE has to be is a filehandle (possibly a glob ref), or
any object that responds to a print() message.
<P><B>Fatal exception</B> raised if unable to open any of the input files,
or if a part contains no data, or if an unsupported encoding is
encountered.
<P><DT><B><A NAME="item:print_header">print_header [OUTHANDLE]</A></B></DT>
<DD>
<I>Instance method.</I>
Print the header of the message to the given output handle,
or to the currently-selected filehandle if none was given.
<P>All OUTHANDLE has to be is a filehandle (possibly a glob ref), or
any object that responds to a print() message.
<P><DT><B><A NAME="item:as_string">as_string</A></B></DT>
<DD>
<I>Instance method.</I>
Return the entire message as a string, with a header and an encoded body.
<P><DT><B><A NAME="item:body_as_string">body_as_string</A></B></DT>
<DD>
<I>Instance method.</I>
Return the encoded body as a string.
<P><I>Note:</I> actually prepares the body by "printing" to a scalar.
Proof that you can hand the <CODE>print*()</CODE> methods any blessed object
that responds to a <CODE>print()</CODE> message.
<P><DT><B><A NAME="item:header_as_string">header_as_string</A></B></DT>
<DD>
<I>Instance method.</I>
Return the header as a string.
</DL>
<P><HR>
<A NAME="Sending"><H3><A HREF="#__TOP__"><IMG SRC="icons/h2bullet.gif" ALT="Top" BORDER="0"></A> Sending</H3></A>
<DL>
<P><DT><B><A NAME="item:send">send</A></B></DT>
<DD>
<P><DT><B><A NAME="item:send">send HOW, HOWARGS...</A></B></DT>
<DD>
<I>Class/instance method.</I>
This is the principle method for sending mail, and for configuring
how mail will be sent.
<P><I>As an instance method</I> (with no arguments), sends the message by whatever
means has been set up (the default is to use the Unix "sendmail" program).
Returns whatever the mail-handling routine returns: this should be true
on success, false/exception on error:
<PRE>
$msg = MIME::Lite->new(From=>...);
$msg->send || die "you DON'T have mail!";
</PRE>
<P><I>As a class method</I> (with a HOW argument and optional HOWARGS), sets up
how the instance method will work for all objects until further notice.
It treats HOW as a facility name, with optional HOWARGS handled by
the facility. There are three facilities:
<DL>
<P><DT><B><A NAME="item:sendmail_SENDMAILCMD">"sendmail", SENDMAILCMD</A></B></DT>
<DD>
Send a message by piping it into the "sendmail" command.
Uses the <CODE>send_by_sendmail()</CODE> method, giving it the SENDMAILCMD.
This usage implements (and deprecates) the <CODE>sendmail()</CODE> method.
=item "smtp", [HOSTNAME]
<P>Send a message by SMTP, using optional HOSTNAME as SMTP-sending host.
Uses the <CODE>send_by_smtp()</CODE> method.
<P><DT><B><A NAME="item:sub_SUBREF_ARGS">"sub", \&SUBREF, ARGS...</A></B></DT>
<DD>
Sends a message MSG by invoking the subroutine SUBREF of your choosing,
with MSG as the first argument, and ARGS following.
</DL>
<P><I>For example:</I> let's say you're on an OS which lacks the usual Unix
"sendmail" facility, but you've installed something a lot like it, and
you need to configure your Perl script to use this "sendmail.exe" program.
Do this following in your script's setup:
<PRE>
MIME::Lite->send('sendmail', "d:\\programs\\sendmail.exe");
</PRE>
<P>Then, whenever you need to send a message $msg, just say:
<PRE>
$msg->send;
</PRE>
<P>That's it. Now, if you ever move your script to a Unix box, all you
need to do is change that line in the setup and you're done.
All of your $msg->send invocations will work as expected.
<P><DT><B><A NAME="item:send_by_sendmail">send_by_sendmail SENDMAILCMD</A></B></DT>
<DD>
<I>Instance method.</I>
Send message via the external "sendmail" program, SENDMAILCMD.
Returns true on success, false or exception on error.
<P><I>Note:</I> this facility will probably only work on Unix systems.
The SENDMAILCMD for this facility must get all its message-specific
information from the standard input.
<P><DT><B><A NAME="item:send_by_smtp">send_by_smtp [ARGS...]</A></B></DT>
<DD>
<I>Instance method.</I>
Send message via SMTP, using Net::SMTP.
The ARGS are sent into Net::SMTP::new(): usually, these are
<PRE>
MAILHOST, OPTION=>VALUE, ...
</PRE>
<P>Note that the list of recipients is taken from the
"To", "Cc" and "Bcc" fields.
<P>Returns true on success, false or exception on error.
<P><DT><B><A NAME="item:sendmail">sendmail COMMAND...</A></B></DT>
<DD>
<I>Class method, DEPRECATED.</I>
Declare the sender to be "sendmail", and set up the "sendmail" command.
<I>You should use send() instead.</I>
</DL>
<P><HR>
<A NAME="Miscellaneous"><H3><A HREF="#__TOP__"><IMG SRC="icons/h2bullet.gif" ALT="Top" BORDER="0"></A> Miscellaneous</H3></A>
<DL>
<P><DT><B><A NAME="item:quiet">quiet ONOFF</A></B></DT>
<DD>
<I>Class method.</I>
Suppress/unsuppress all warnings coming from this module.
<PRE>
quiet MIME::Lite 1; # I know what I'm doing
</PRE>
<P>I recommend that you include that comment as well. And while
you type it, say it out loud: if it doesn't feel right, then maybe
you should reconsider the whole line. <CODE>;-)</CODE>
</DL>
<P><HR>
<A NAME="NOTES"><H2><A HREF="#__TOP__"><IMG SRC="icons/h1bullet.gif" ALT="Top" BORDER="0"></A> NOTES</H2></A>
<P><HR>
<A NAME="Limitations"><H3><A HREF="#__TOP__"><IMG SRC="icons/h2bullet.gif" ALT="Top" BORDER="0"></A> Limitations</H3></A>
<P>This is "lite", after all...
<UL>
<P><LI>
<P>There's no parsing. Get MIME-tools if you need to parse MIME messages.
<P><LI>
<P>MIME::Lite messages are currently <I>not</I> interchangeable with
either Mail::Internet or MIME::Entity objects. This is a completely
separate module.
<P><LI>
<P>A content-length field is only inserted if the encoding is binary,
the message is a singlepart, and all the document data is available
at <CODE>build()</CODE> time by virtue of residing in a simple path, or in-core.
Since content-length is not a standard MIME field anyway (that's right, kids:
it's not in the MIME RFCs, it's an HTTP thing), this seems pretty fair.
<P><LI>
<P>MIME::Lite alone cannot help you lose weight. You must supplement
your use of MIME::Lite with a healthy diet and exercise.
</UL>
<P><HR>
<A NAME="Cheap_and_easy_mailing"><H3><A HREF="#__TOP__"><IMG SRC="icons/h2bullet.gif" ALT="Top" BORDER="0"></A> Cheap and easy mailing</H3></A>
<P>I thought putting in a default "sendmail" invocation wasn't too bad an
idea, since a lot of Perlers are on UNIX systems. The default arguments
to sendmail (which you can change) are:
<PRE>
-t Scan message for To:, Cc:, Bcc:, etc.
-oi Do NOT treat a single "." on a line as a message terminator.
As in, "-oi vey, it truncated my message... why?!"
-oem On error, mail back the message (I assume to the
appropriate address, given in the header).
When mail returns, circle is complete. Jai guru deva -oem.
</PRE>
<P>If you're not on a Unix system, or if you'd just rather send mail
some other way, check out the <CODE>send()</CODE> method. There's built in
support for SMTP delivery, or you can slip in your own hooks.
<P><HR>
<A NAME="Under_the_hood"><H3><A HREF="#__TOP__"><IMG SRC="icons/h2bullet.gif" ALT="Top" BORDER="0"></A> Under the hood</H3></A>
<P>This class treats a MIME header in the most abstract sense,
as being a collection of high-level attributes. The actual
RFC-822-style header fields are not constructed until it's time
to actually print the darn thing.
<P><HR>
<A NAME="WARNINGS"><H2><A HREF="#__TOP__"><IMG SRC="icons/h1bullet.gif" ALT="Top" BORDER="0"></A> WARNINGS</H2></A>
<P><HR>
<A NAME="MIME-_and_non-MIME_header_fields"><H3><A HREF="#__TOP__"><IMG SRC="icons/h2bullet.gif" ALT="Top" BORDER="0"></A> MIME- and non-MIME header fields</H3></A>
<P><B>Important:</B> the MIME attributes are stored and manipulated separately
from the message header fields; when it comes time to print the
header out, <I>any explicitly-given header fields override the ones that
would be created from the MIME attributes.</I> That means that this:
<PRE>
### DANGER ### DANGER ### DANGER ### DANGER ### DANGER ###
$msg->add("Content-type", "text/html; charset=US-ASCII");
</PRE>
<P>will set the exact <CODE>"Content-type"</CODE> field in the header I write,
<I>regardless of what the actual MIME attributes are.</I>
<P><I>This feature is for experienced users only,</I> as an escape hatch in case
the code that normally formats MIME header fields isn't doing what
you need. And, like any escape hatch, it's got an alarm on it:
MIME::Lite will warn you if you attempt to <CODE>set()</CODE> or <CODE>replace()</CODE>
any MIME header field. Use <CODE>attr()</CODE> instead.
<P><HR>
<A NAME="Lines_consisting_of_a_single_dot"><H3><A HREF="#__TOP__"><IMG SRC="icons/h2bullet.gif" ALT="Top" BORDER="0"></A> Lines consisting of a single dot</H3></A>
<P>Julian Haight noted that MIME::Lite allows you to compose messages
with lines in the body consisting of a single ".".
This is true: it should be completely harmless so long as "sendmail"
is used with the -oi option (see <A HREF="#Cheap_and_easy_mailing">Cheap and easy mailing</A>).
<P>However, I don't know if using Net::SMTP to transfer such a message
is equally safe. Feedback is welcomed.
<P>My perspective: I don't want to magically diddle with a user's
message unless absolutely positively necessary.
Some users may want to send files with "." alone on a line;
my well-meaning tinkering could seriously harm them.
<P><HR>
<A NAME="A_MIME_PRIMER"><H2><A HREF="#__TOP__"><IMG SRC="icons/h1bullet.gif" ALT="Top" BORDER="0"></A> A MIME PRIMER</H2></A>
<P><HR>
<A NAME="Content_types"><H3><A HREF="#__TOP__"><IMG SRC="icons/h2bullet.gif" ALT="Top" BORDER="0"></A> Content types</H3></A>
<P>The "Type" parameter of <CODE>build()</CODE> is a <I>content type</I>.
This is the actual type of data you are sending.
Generally this is a string of the form <CODE>"majortype/minortype"</CODE>.
<P>Here are the major MIME types.
A more-comprehensive listing may be found in RFC-2046.
<DL>
<P><DT><B><A NAME="item:application">application</A></B></DT>
<DD>
Data which does not fit in any of the other categories, particularly
data to be processed by some type of application program.
<CODE>application/octet-stream</CODE>, <CODE>application/gzip</CODE>, <CODE>application/postscript</CODE>...
<P><DT><B><A NAME="item:audio">audio</A></B></DT>
<DD>
Audio data.
<CODE>audio/basic</CODE>...
<P><DT><B><A NAME="item:image">image</A></B></DT>
<DD>
Graphics data.
<CODE>image/gif</CODE>, <CODE>image/jpeg</CODE>...
<P><DT><B><A NAME="item:message">message</A></B></DT>
<DD>
A message, usually another mail or MIME message.
<CODE>message/rfc822</CODE>...
<P><DT><B><A NAME="item:multipart">multipart</A></B></DT>
<DD>
A message containing other messages.
<CODE>multipart/mixed</CODE>, <CODE>multipart/alternative</CODE>...
<P><DT><B><A NAME="item:text">text</A></B></DT>
<DD>
Textual data, meant for humans to read.
<CODE>text/plain</CODE>, <CODE>text/html</CODE>...
<P><DT><B><A NAME="item:video">video</A></B></DT>
<DD>
Video or video+audio data.
<CODE>video/mpeg</CODE>...
</DL>
<P><HR>
<A NAME="Content_transfer_encodings"><H3><A HREF="#__TOP__"><IMG SRC="icons/h2bullet.gif" ALT="Top" BORDER="0"></A> Content transfer encodings</H3></A>
<P>The "Encoding" parameter of <CODE>build()</CODE>.
This is how the message body is packaged up for safe transit.
<P>Here are the 5 major MIME encodings.
A more-comprehensive listing may be found in RFC-2045.
<DL>
<P><DT><B><A NAME="item:7bit">7bit</A></B></DT>
<DD>
Basically, no <I>real</I> encoding is done. However, this label guarantees that no
8-bit characters are present, and that lines do not exceed 1000 characters
in length.
<P><DT><B><A NAME="item:8bit">8bit</A></B></DT>
<DD>
Basically, no <I>real</I> encoding is done. The message might contain 8-bit
characters, but this encoding guarantees that lines do not exceed 1000
characters in length.
<P><DT><B><A NAME="item:binary">binary</A></B></DT>
<DD>
No encoding is done at all. Message might contain 8-bit characters,
and lines might be longer than 1000 characters long.
<P>The most liberal, and the least likely to get through mail gateways.
Use sparingly, or (better yet) not at all.
<P><DT><B><A NAME="item:base64">base64</A></B></DT>
<DD>
Like "uuencode", but very well-defined. This is how you should send
essentially binary information (tar files, GIFs, JPEGs, etc.).
<P><DT><B><A NAME="item:quoted-printable">quoted-printable</A></B></DT>
<DD>
Useful for encoding messages which are textual in nature, yet which contain
non-ASCII characters (e.g., Latin-1, Latin-2, or any other 8-bit alphabet).
</DL>
<P><HR>
<A NAME="CHANGE_LOG"><H2><A HREF="#__TOP__"><IMG SRC="icons/h1bullet.gif" ALT="Top" BORDER="0"></A> CHANGE LOG</H2></A>
<P><B>Current version:</B>
$Id: Lite.pm,v 1.140 2000/04/27 06:31:54 eryq Exp $
<DL>
<P><DT><B><A NAME="item:Version">Version 1.140</A></B></DT>
<DD>
Fixed bug in support for "To", "Cc", and "Bcc" in send_by_smtp():
multiple (comma-separated) addresses should now work fine.
We try real hard to extract addresses from the flat text strings.
<I>Thanks to John Mason for motivating this change.</I>
<P>Added automatic verification that attached data files exist,
done immediately before the "send" action is invoked.
To turn this off, set $MIME::Lite::AUTO_VERIFY to false.
<P><DT><B><A NAME="item:Version">Version 1.137</A></B></DT>
<DD>
Added support for "Cc" and "Bcc" in send_by_smtp().
To turn this off, set $MIME::Lite::AUTO_CC to false.
<I>Thanks to Lucas Maneos for the patch, and tons of others for
the suggestion.</I>
<P>Chooses a better default content-transfer-encoding if the content-type
is "image/*", "audio/*", etc.
To turn this off, set $MIME::Lite::AUTO_ENCODE to false.
<I>Thanks to many folks for the suggestion.</I>
<P>Fixed bug in QP-encoding where a non-local <CODE>$_</CODE> was being modified.
<I>Thanks to Jochen Stenzel for finding this very obscure bug!</I>
<P>Removed references to <CODE>$`</CODE>, <CODE>$'</CODE>, and <CODE>$&</CODE> (bad variables
which slow things down).
<P>Added an example of how to send HTML files with enclosed in-line
images, per popular demand.
<P><DT><B><A NAME="item:Version">Version 1.133</A></B></DT>
<DD>
Fixed bug in "Data" handling: arrayrefs were not being handled
properly.
<P><DT><B><A NAME="item:Version">Version 1.130</A></B></DT>
<DD>
Added much larger and more-flexible send() facility.
<I>Thanks to Andrew McRae (and Optimation New Zealand Ltd)
for the Net::SMTP interface. Additional thanks to the many folks
who requested this feature.</I>
<P>Added get() method for extracting basic attributes.
<P>New... "t" tests!
<P><DT><B><A NAME="item:Version">Version 1.124</A></B></DT>
<DD>
Folded in filehandle (FH) support in build/attach.
<I>Thanks to Miko O'Sullivan for the code.</I>
<P><DT><B><A NAME="item:Version">Version 1.122</A></B></DT>
<DD>
MIME::Base64 and MIME::QuotedPrint are used if available.
<P>The 7bit encoding no longer does "escapes"; it merely strips 8-bit characters.
<P><DT><B><A NAME="item:Version">Version 1.121</A></B></DT>
<DD>
Filename attribute is now no longer ignored by build().
<I>Thanks to Ian Smith for finding and patching this bug.</I>
<P><DT><B><A NAME="item:Version">Version 1.120</A></B></DT>
<DD>
Efficiency hack to speed up MIME::Lite::IO_Scalar.
<I>Thanks to David Aspinwall for the patch.</I>
<P><DT><B><A NAME="item:Version">Version 1.116</A></B></DT>
<DD>
Small bug in our private copy of encode_base64() was patched.
<I>Thanks to Andreas Koenig for pointing this out.</I>
<P>New, prettier way of specifying mail message headers in <CODE>build()</CODE>.
<P>New quiet method to turn off warnings.
<P>Changed "stringify" methods to more-standard "as_string" methods.
<P><DT><B><A NAME="item:Version">Version 1.112</A></B></DT>
<DD>
Added <CODE>read_now()</CODE>, and <CODE>binmode()</CODE> method for our non-Unix-using brethren:
file data is now read using binmode() if appropriate.
<I>Thanks to Xiangzhou Wang for pointing out this bug.</I>
<P><DT><B><A NAME="item:Version">Version 1.110</A></B></DT>
<DD>
Fixed bug in opening the data filehandle.
<P><DT><B><A NAME="item:Version">Version 1.102</A></B></DT>
<DD>
Initial release.
<P><DT><B><A NAME="item:Version">Version 1.101</A></B></DT>
<DD>
Baseline code.
</DL>
<P><HR>
<A NAME="TERMS_AND_CONDITIONS"><H2><A HREF="#__TOP__"><IMG SRC="icons/h1bullet.gif" ALT="Top" BORDER="0"></A> TERMS AND CONDITIONS</H2></A>
<P>Copyright (c) 1997 by Eryq.
Copyright (c) 1998 by ZeeGee Software Inc.
All rights reserved. This program is free software; you can redistribute
it and/or modify it under the same terms as Perl itself.
<P>This software comes with <B>NO WARRANTY</B> of any kind.
See the COPYING file in the distribution for details.
<P><HR>
<A NAME="NUTRITIONAL_INFORMATION"><H2><A HREF="#__TOP__"><IMG SRC="icons/h1bullet.gif" ALT="Top" BORDER="0"></A> NUTRITIONAL INFORMATION</H2></A>
<P>For some reason, the US FDA says that this is now required by law
on any products that bear the name "Lite"...
<PRE>
Serving size: 1 module
Servings per container: 1
Calories: 0
Fat: 0g
Saturated Fat: 0g
</PRE>
<PRE>
Warning: for consumption by hardware only! May produce
indigestion in humans if taken internally.
</PRE>
<P><HR>
<A NAME="AUTHOR"><H2><A HREF="#__TOP__"><IMG SRC="icons/h1bullet.gif" ALT="Top" BORDER="0"></A> AUTHOR</H2></A>
<P>Eryq (<I><FILE><A HREF="mailto:eryq@zeegee.com">eryq@zeegee.com</A></FILE></I>).
President, ZeeGee Software Inc. (<I><FILE><A HREF="http://www.zeegee.com">http://www.zeegee.com</A></FILE></I>).
<P>Created: 11 December 1996. Ho ho ho.
<P><HR>
<ADDRESS><FONT SIZE=-1>
Generated Thu Apr 27 02:32:37 2000 by cvu_pod2html
</FONT></ADDRESS>
</BODY>
</HTML>