The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

App::Framework::Feature::Mail - Send mail

SYNOPSIS

  use App::Framework '+Mail' ;

DESCRIPTION

Provides a simplified mail interface, and application error auto-mailing.

When used as a mail interface, this feature is accessed in the same manner as any other (e.g. see App::Framework::Feature::Args).

The accessor function ("mail") returns the mail object if no parameters are specified; otherwise it will send a mail:

        $app->Mail("This is a test",
                'from'          => 'someone@domain.co.uk',
                'to'            => 'afriend@domain.com',
                'subject'       => 'a test',
        ) ;
 

Default settings may be set at the start of an application so that only specific parameters need to be added:

        $app->Mail()->set(
                'from'          => 'someone@domain.co.uk',
                'error_to'      => 'someone@domain.co.uk',
                'err_level' => 'warning',
        ) ;

        ## send a mail to 'afriend@domain.com'
        $app->Mail("This is a test",
                'to'            => 'afriend@domain.com',
                'subject'       => 'a test',
        ) ;

        ...
        
        ## send another - still goers to 'afriend@domain.com'
        $app->Mail("This is another test",
                'subject'       => 'another test',
        ) ;

An additional capability is that this feature can automatically send emails of any errors. To do this you first of all need to specify the 'error_to' recipient, and then set the 'err_level'. The 'err_level' setting specifies the type of error that will generate an email. For example, setting 'err_level' to "warning" means all warnings AND errors will result in emails; but notes will not (see App::Framework::Base::Object::ErrorHandle for types).

This feature also automatically adds mail-related command line options to allow a user to specify the field settings for themselves (or an application may over ride with their own defaults).

Note that the 'to' and 'error_to' fields may be a comma seperated list of mail recipients.

ADDITIONAL COMMAND LINE OPTIONS

This extension adds the following additional command line options to any application:

-mail-from - Mail sender (required)

Email sender

-mail-to - Mail recipient(s) (required)

Email recipient. Where there are multiple recipients, they should be set as a comma seperated list of email addresses

-mail-error-to - Error mail recipient(s)

Email recipient for errors. If set, program errors are sent to this email.

-mail-err-level - Error level for mails

Set the minium error level that triggers an email. Level can be: note, warning, error

-mail-subject - Mail subject

Optional mail subject line

-mail-host - Mail host

Mailing host. If not specified uses 'localhost'

FIELDS

The following fields should be defined either in the call to 'new()', as part of a 'set()' call, or called by their accessor method (which is the same name as the field):

from - Mail sender (required)

Email sender

to - Mail recipient(s) (required)

Email recipient. Where there are multiple recipients, they should be set as a comma seperated list of email addresses

error_to - Error mail recipient(s)

Email recipient for errors. If set, program errors are sent to this email.

err_level - Error level for mails

Set the minium error level that triggers an email. Level can be: note, warning, error

subject - Mail subject

Optional mail subject line

host - Mail host

Mailing host. If not specified uses 'localhost'

CONSTRUCTOR

new([%args])

Create a new Mail.

The %args are specified as they would be in the set method (see "Fields").

CLASS METHODS

init_class([%args])

Initialises the Mail object class variables.

OBJECT METHODS

mail($content [, %args])

Send some mail stored in $content. $content may either be a string (containing newlines), or an ARRAY ref.

Optionally %args may be specified (to set 'subject' etc).

If no arguments are specified then just returns the mail object.

Mail([%args])

Alias to "mail"

application_entry()

Called by the application framework at the start of the application.

This method checks for the user specifying any of the options described above (see "ADDITIONAL COMMAND LINE OPTIONS") and handles them if so.

catch_error_entry($error)

Send some mail stored in $content. $content may either be a string (containing newlines), or an ARRAY ref.

Optionally %args may be specified (to set 'subject' etc)

DIAGNOSTICS

Setting the debug flag to level 1 prints out (to STDOUT) some debug messages, setting it to level 2 prints out more verbose messages.

AUTHOR

Steve Price <sdprice at cpan.org>

BUGS

None that I know of!