NAME

Mail::Builder::Image - Class for handling inline images

SYNOPSIS

use Mail::Builder::Image;

my $image1 = Mail::Builder::Image->new({
    file  => 'path/to/image.png',
    id    => 'location',
});

my $image2 = Mail::Builder::Image->new($fh);

my $image1_entity = $image1->serialize;

DESCRIPTION

This class handles inline images that should be displayed in html e-mail messages.

METHODS

Constructor

new

The constructor can be called in multiple ways

Mail::Builder::Image->new({
    file       => Path | Path::Class::File | IO::File | FH | ScalarRef,
    [ id       => Image id, ]
    [ mimetype => MIME type, ]
})
OR
Mail::Builder::Image->new(
   Path | Path::Class::File | IO::File | FH | ScalarRef
   [, Image id [, MIME type ]]
)

See Accessors for more details.

Public Methods

serialize

Returns the image file as a MIME::Entity object.

filename

If possible, returns the filename of the image file as a Path::Class::File object.

filecontent

Returns the content of the image file.

filehandle

If possible, returns a filehandle for the image file as a IO::File object.

Accessors

id

ID of the file. If no id is provided the lowercase filename without the extension will be used as the ID.

The ID is needed to reference the image in the e-mail body:

<img src="cid:invitation_location"/>

mimetype

Mime type of the image. Valid types are

  • image/gif

  • image/jpeg

  • image/png

If not provided the mime type is determined by analyzing the filename extension and file content.

file

Image. Can be a

  • Path (or a Path::Class::File object)

  • Filehandle (or an IO::File object)

  • ScalarRef containing the image data

AUTHOR

Maroš Kollár
CPAN ID: MAROS
maros [at] k-1.com
http://www.k-1.com