NAME
Mail::Builder - Easily create e-mails with attachments, html and inline
images
SYNOPSIS
use Mail::Builder;
my $mail = Mail::Builder->new();
$mail->from('mightypirate@meele-island.mq','Guybrush Threepwood');
$mail->to->add('manuel.calavera@dod.mx','Manuel Calavera');
$mail->cc->add('glotis@dod.mx');
$mail->subject('Party at Sam\'s place');
$mail->htmltext('
Party invitation
... ');
$mail->attachment->add('direction_samandmax.pdf');
# Send it with your favourite module (e.g. Email::Send)
my $mailer = Email::Send->new({mailer => 'Sendmail'})->send($mail->stringify);
# Or mess with the MIME::Entity objects
my $mime = $mail->build_message;
DESCRIPTION
This module helps you to build e-mails with attachments, inline images,
multiple recipients, ... without having to worry about the underlying
MIME stuff. Mail::Builder relies heavily on the MIME::Entity module from
the MIME::Tools distribution.
The module will create the correct MIME bodies, headers and containers
(multipart/mixed, multipart/related, multipart/alternative) depending on
if you use attachments, HTML text and inline images.
Addresses, attachments and inline images are handled as objects by
helper classes:
* "Address: Mail::Builder::Address"
Stores an e-mail address and a display name.
* Attachments: Mail::Builder::Attachment::File and
Mail::Builder::Attachment::Data
This classes manage attachments which can be created either from
files on the filesystem or from data in memory.
* Inline images:Mail::Builder::Image
The Address: Mail::Builder::Image class manages images that should
be displayed in the e-mail body.
* "Address: Mail::Builder::List"
Helper class for handling list of varoius items (recipient lists,
attachment lists, ...)
METHODS
Constructors
new
This is a simple constructor. It does not expect any parameters.
Public methods
stringify
Returns the e-mail message as a string. This string can be passed to
modules like Email::Send.
build_message
Returns the e-mail message as a MIME::Entity object. You can mess
arround with the object, change parts, ... as you wish.
Every time you call build_message the MIME::Entity object will be
created, which can take some time if you are sending the e-mail to many
recipients. In order to increase the speed of the module the
Mail::Builder::Attachment and Mail::Builder::Image entities will be
cached and only rebuilt if something has changed.
Accessors
from
This is a simple constructor. It does not expect any parameters.
from, returnpath, reply
These accessors set/return the from and reply address as well as the
returnpath for bounced messages.
$obj->from(EMAIL[,NAME])
OR
$obj->from(Mail::Builder::Address)
This accessor always returns a Mail::Builder::Address object. If
parameters are provided the object will be replaced. You can either
suppy a Mail::Builder::Address object, or an e-mail address with an
optional name.
to, cc, bcc
$obj->to(Mail::Builder::List)
OR
$obj->to(Mail::Builder::Address)
OR
$obj->to(EMAIL[,NAME])
OR
$obj->to->add(EMAIL[,NAME])
OR
$obj->to->add(Mail::Builder::Address)
This accessor always returns a Mail::Builder::List object. If you supply
a Mail::Builder::List the object will be replaced. If you supply a
Mail::Builder::Address object or an e-mail address (with an optional
name), the new address will be appended to the list of recipients. The
Mail::Builder::List package provides some basic methods for manipulating
the list of recipients.
organization
Accessor for the name of the senders organisation.
prioriy
Priority accessor. Accepts values from 1 to 5. The default priority is
3.
subject
e-mail subject accessor.
charset
charset accessor. Defaults to utf8.
htmltext
HTML mail body accessor.
plaintext
Plaintext mail body accessor. This text will be autogenerated from
htmltext if not provided by the user. Simple formating (e.g. ,
) will be converted to pseudo formating.
The following html tags will be transformed:
* I, EM
Italic text will be sorounded by underscores. (_)
* H1, H2, H3, ...
Headnlines will be replaced by two equal signs (=)
* STRONG, B
Bold text will be marked by stars (*)
* HR
A horizontal rule is replaced by 60 dashes.
* BR
Single linebreak
* P, DIV
Duoble linebreak
* UL, OL
All list items will be indented and prefixed with a start (*) or an
index number.
attachment
$obj->attachment(Mail::Builder::List)
OR
$obj->attachment(Mail::Builder::Attachment)
OR
$obj->attachment(PATH[,NAME,MIME])
OR
$obj->attachment->add(PATH[,NAME,MIME])
OR
$obj->attachment->add(Mail::Builder::Attachment)
This accessor always returns a Mail::Builder::List object. If you supply
a Mail::Builder::List object it will be replaced. If you supply a
Mail::Builder::Attachment object or a path to a file (with an optional
name an mime type), the new attachment will be appended to the list.
image
$obj->image(Mail::Builder::List)
OR
$obj->image(Mail::Builder::Image)
OR
$obj->image(PATH[,ID])
OR
$obj->image->add(PATH[,ID])
OR
$obj->image->add(Mail::Builder::Image)
This accessor always returns a Mail::Builder::List object. If you supply
a Mail::Builder::List object it will be replaced. If you supply a
Mail::Builder::Image object or a path to a file (with an optional id),
the new image will be appended to the list.
You can embed the image into the html mail body code by referencing the
ID. If you didn't provide an ID the lowercase filename without the
extension will be used.
Only jpg, gif and png images may be added as inline images.
SUPPORT
Please report any bugs or feature requests to
"bug-mail-builder@rt.cpan.org", or through the web interface at
. I will be notified, and then you'll automatically
be notified of progress on your bug as I make changes.
AUTHOR
Maros Kollar
CPAN ID: MAROS
maros [at] k-1.com
http://www.k-1.com
COPYRIGHT
Mail::Builder is Copyright (c) 2006,2007 Maroš Kollár. All rights
reserved.
This program is free software; you can redistribute it and/or modify it
under the same terms as Perl itself.
The full text of the license can be found in the LICENSE file included
with this module.
SEE ALSO
The Mime::Entity module in the Mime::Tools distribution.