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('<h1>Party invitation</h1> ... ');
$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 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:

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.

This method is just a shortcut to $mb-&gt;build_message-&gt;stringify

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 bulk e-mails. In order to increase the processing speed Mail::Builder::Attachment and Mail::Builder::Image entities will be cached and only rebuilt if something has changed.

Accessors

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])

This accessor always returns a Mail::Builder::List object. If you supply a Mail::Builder::List the list will be replaced.

If you supply a Mail::Builder::Address object or an e-mail address (with an optional name),the current list will be reset and the new address will be added.

The Mail::Builder::List package provides some basic methods for manipulating the list of recipients.

If you want to append an additional address to the list use

$obj->to->add(EMAIL[,NAME])
OR
$obj->to->add(Mail::Builder::Address)

messageid

Message ID of the e-mail. Read only and only available after the build_message or stingify methods have been called.

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. Must be specified.

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. <strong>, <em>) will be converted to pseudo formating.

The following html tags will be transformed:

  • I, EM

    Italic text will be surounded by underscores. (_)

  • H1, H2, H3, ...

    Headlines 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

    Double 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])

This accessor always returns a Mail::Builder::List object. If you supply a Mail::Builder::List the list will be replaced.

If you pass a Mail::Builder::Attachment object or a scalar path (with an optional name an mime type) the current list will be reset and the new attachment will be added.

The Mail::Builder::List package provides some basic methods for manipulating the list of recipients.

If you want to append an additional attachment to the list use

$obj->attachment->add(PATH[,NAME,MIME])
OR
$obj->attachment->add(Mail::Builder::Attachment)

image

$obj->image(Mail::Builder::List)
OR
$obj->image(Mail::Builder::Image)
OR
$obj->image(PATH[,ID])

This accessor always returns a Mail::Builder::List object. If you supply a Mail::Builder::List the list will be replaced.

If you pass a Mail::Builder::Image object or a scalar path (with an optional id) the current list will be reset and the new image will be added.

The Mail::Builder::List package provides some basic methods for manipulating the list of recipients.

If you want to append an additional attachment to the list use

$obj->image->add(PATH[,ID])
OR
$obj->image->add(Mail::Builder::Image)

You can embed the image into the html mail body code by referencing the ID. If you don't provide an ID the lowercase filename without the extension will be used as the ID.

<img src="cid:logo"/>

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 http://rt.cpan.org. 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) 2007,2008 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.

1 POD Error

The following errors were encountered while parsing the POD:

Around line 661:

Non-ASCII character seen before =encoding in 'Maroš'. Assuming UTF-8