NAME

Emailesque - Lightweight To-The-Point Email

VERSION

version 1.103640

SYNOPSIS

use Emailesque qw/email/;

email {
  to      => '...',
  from    => '...',
  subject => '...',
  message => '...',
  attach  => [
      '/path/to/file' => 'filename'
  ]
};

or

use Emailesque;

my $message = Emailesque->new({ from => '...' });

$message->send({
  to      => '...',
  subject => '...',
  message => '...',
});

Important Note! The default email format is plain-text, this can be changed to html by setting the option 'type' to 'html' in the hashref passed to the new function or email keyword. The following are options that can be passed within the hashref of arguments:

# send message to
to => $email_recipient

# send messages from
from => $mail_sender

# email subject
subject => 'email subject line'

# message body
message => 'html or plain-text data'
message => {
    text => $text_message,
    html => $html_messase,
    # type must be 'multi'
}

# email message content type
type => 'text'
type => 'html'
type => 'multi'

# carbon-copy other email addresses
cc => 'user@site.com'
cc => 'user_a@site.com, user_b@site.com, user_c@site.com'
cc => join ', ', @email_addresses

# blind carbon-copy other email addresses
bcc => 'user@site.com'
bcc => 'user_a@site.com, user_b@site.com, user_c@site.com'
bcc => join ', ', @email_addresses

# specify where email responses should be directed
reply_to => 'other_email@website.com'

# attach files to the email
attach => [
    $file_location => $attachment_name,
]

# send additional (specialized) headers
headers => {
    "X-Mailer" => "SPAM-THE-WORLD-BOT 1.23456789"
}

DESCRIPTION

Provides an easy way of handling text or html email messages with or without attachments. Simply define how you wish to send the email, then call the email keyword passing the necessary parameters as outlined above.

CODE RECIPES

# Handle Email Failures

my $msg = email {
        to      => '...',
        subject => '...',
        message => $msg,
        attach  => [
            '/path/to/file' => 'filename'
        ]
    };
    
die $msg->{string} if $msg->{type} eq 'failure';

# Add More Email Headers

email {
    to      => '...',
    subject => '...',
    message => $msg,
    headers => {
        "X-Mailer" => 'This fine Dancer application',
        "X-Accept-Language" => 'en'
    }
};

# Send Text and HTML Email together

email {
    to      => '...',
    subject => '...',
    type    => 'multi',
    message => {
        text => $txt,
        html => $html,
    }
};

CONFIG COOKBOOK

 # Send mail via SMTP with SASL authentication
 
 {
     ...,
     driver  => 'smtp',
     host    => 'smtp.website.com',
     user    => 'account@gmail.com',
     pass    => '****'
 }
 
 # Send mail to/from Google (gmail)
 
 {
     ...,
     ssl     => 1,
     driver  => 'smtp',
     host    => 'smtp.website.com',
     port    => 465,
     user    => 'account@gmail.com',
     pass    => '****'
 }

 # Send mail to/from Google (gmail) using TLS
 
 {
     ...,
     tls     => 1,
     driver  => 'smtp',
     host    => 'smtp.website.com',
     port    => 587,
     user    => 'account@gmail.com',
     pass    => '****'
 }
     
 # Debug email server communications
 
 {
     ...,
     debug => 1
 }
     
 # Set default headers to be issued with every message
 
 {
     ...,
     from => '...',
     subject => '...',
     headers => {
         'X-Mailer' => 'MyApp 1.0',
         'X-Accept-Language' => 'en'
     }
 }
 
 # Send email using sendmail
 
 {
     ...,
     driver  => 'sendmail',
     path    => '/usr/bin/sendmail',
 }

AUTHOR

Al Newkirk <awncorp@cpan.org>

COPYRIGHT AND LICENSE

This software is copyright (c) 2010 by awncorp.

This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.