ePages 6.10 - DE_EPAGES/Mail/API/Mail.pm

Package DE_EPAGES::Mail::API::Mail

This package is used for processing e-mails. It simplifies creation of HTML mails and mails with attachments.

Example
my $Connection = DE_EPAGES::Mail::API::SMTP->new( 'mail', 25 );
$Connection->openConnection;
my $Mail = DE_EPAGES::Mail::API::Mail->new( {
    'FROM' => 'Mailer <sender@domain.com>',
    'TO'   => ['Recipient1@provider1.com','Name <Recipient2@provider2.com>', ],
    'SUBJECT' => 'Test Subject'
} );
$Mail->addText({'content'   => 'This is Plain Text'});
$Mail->send( $Connection );
$Connection->closeConnection;

Functions

addAttachment
addHTML
addHTMLAttachment
addText
convertHtml2Plain
createMail
getHeader
new
send

addAttachment

Adds attachments to the mail.

Syntax
$Mail->addAttachment( $ahParams );
Example
my $hFile = {
    'filename' => '/tmp/Setup.exe',
    'type'     => 'Application/Octet-stream',
};
$Mail->addAttachment( [ $hFile ] );
Input
$ahParams (reference to array of hashes)
with following keys:
  • filename - the filename - string
  • type - content type (optional)
    default:Application/Octet-stream - string

addHTML

Adds an HTML element to the mail.

Syntax
$Mail->addHTML( $hParams );
Example
$Mail->addHTML({
    'content'         => '<body>content</body>',
    'encoding'        => 'quoted-printable',
    'type'            => 'text/html',
    'type.charset'    => 'utf-8',
    'html2plain'      => 1,
    'alttext'         => '',
    'altencoding'     => 'quoted-printable',
    'alt.type.charset'=> 'utf-8',
});
Input
$hParams (reference to hash)
with following keys:
  • content - HTML text - string
  • encoding - encoding (optional, default:quoted-printable) - string
  • type - content type (optional, default:text/html) - string
  • type.charset- content type charset (optional, default:utf8) - string
  • html2plain - create alternate text from html
    flag 1/0 (optional) - boolean
  • alttext - alternate text if not html2plain
    (optional, default: '') - string
  • altencoding - encoding of the alternate text
    (optional, default: quoted-printable) - string
  • alt.type.charset - content type charset for alternate text
    (optional, default:utf8) - string

addHTMLAttachment

Adds inline attachments (images, style sheets etc.) to an HTML e-mail.

Syntax
$Mail->addHTMLAttachment( $ahParams );
Example
my $hStyle = {
    'filename'   => '/tmp/style.css',
    'includeid'  => '__reference_id_style_',
    'type'       => 'text/css',
};
my $hImage = {
    'filename'   => '/tmp/image.jpg',
    'includeid'  => '__reference_id_image_',
    'type'       => 'image/jpg',
};
$Mail->addHTMLAttachment( [ $hStyle, $hImage ] );
Input
$ahParams (reference to array of hashes)
with following keys:
  • filename - the filename - string
  • includeid - unique id for the file ref. in html - string
  • type - content type (optional)
    default:Application/Octet-stream - string

addText

Adds a text element to the mail.

Syntax
$Mail->addText( $hParams );
$Mail->addText({
    'content'     => 'Das ist Plain Text',
    'encoding'    => 'quoted-printable',
    'type'        => 'text/plain',
    'type.charset'=> 'utf-8',
});
Input
$hParams (reference to hash)
with following keys:
  • content - text to add - string
  • encoding - encoding (optional, default:quoted-printable) - string
  • type - content type (optional, default:text/plain) - string
  • type.charset - character encoding (optional, default:utf-8) - string

convertHtml2Plain

Creates plain text from HTML.

Syntax
my $Plain = $Mail->convertHtml2Plain($HTML);
Input
$HTML (string)
html string
Return
$Plain (string)
plain text

createMail

Creates the MIME body of the e-mail from the previously added text and attachment elements.

Syntax
$MailBody = $Mail->createMail();
Example
$Connection->sendDataToSMTP( $Mail->createMail(), $Mail->getHeader() );
Return
$MailBody (string)
the Mail content

getHeader

Returns the parameters for the e-mail header.

Syntax
$hParams = $Mail->getHeader();
Return
$hHeader (ref.hash)
header parameters, see new

new

Creates a new object of DE_EPAGES::Mail::API::Mail with header parameters.

Syntax
$Mail = DE_EPAGES::Mail::API::Mail->new($hParams);
my $Mail = DE_EPAGES::Mail::API::Mail->new( {
         'HEADER_ENC'   => 'iso-8859-1'
         'SUBJECT'      => 'the Subject'
         'FROM'         => 'Sender <mailer@epages.de>',
         'NOTIFY'       => 1,
         'REPLY'        => 'Replyer <replyaddress@epages.de>',
         'SkipBadRecipients'   => 1,
         'TO'           => ['Recipient <rcpt@epages.de>',
                             'Recipient1 <rcpt1@epages.de>'
                           ],
         'CC'           => ['CC1 <ccrcpt1@epages.de>',
                             'CC2 <ccrcpt2@epages.de>'
                           ],
         'BCC'          => ['BCC1 <bccrcpt1@epages.de>',
                             'BCC2 <bccrcpt2@epages.de>'
                           ]
        });
Input
$hParams (reference to hash)
e-mail header parameters with following keys:
  • HEADER_ENC - utf8, iso-8859-1,... (optional) default='utf-8' - string
  • SUBJECT - the mail subject - string
  • FROM - the sender "Phrase <name@host.domain>" - string
  • NOTIFY - read notification to sender 1/0 (optional)- boolean
  • REPLY - the reply address 'Phrase <name@host.domain>' (optional)- string
  • TO - the recipients 'Phrase <name@host.domain>' (optional)- array
  • SkipBadRecipients - 1/0 ignore recipient addresses like
    'name@epa@ges.de' (optional)- boolean
  • CC - the CC recipients 'Phrase <name@host.domain>' (optional)- array
  • BCC - the BCC recipients 'Phrase <name@host.domain>'(optional)- array
Return
$Mail (object)
mail object

send

Sends the mail to the given SMTP Server Connection.

Syntax
$Mail->send($Connection);
Input
$Connection (object)
SMTP server Connection, see
DE_EPAGES::Mail::API::SMTP