NAME
Test::Reporter::POEGateway::Mailer - Sends reports via a configured mailer
SYNOPSIS
#!/usr/bin/perl
use strict; use warnings;
use Test::Reporter::POEGateway::Mailer;
# A sample using SMTP+SSL with AUTH
Test::Reporter::POEGateway::Mailer->spawn(
'mailer' => 'SMTP',
'mailer_conf' => {
'smtp_host' => 'smtp.mydomain.com',
'smtp_opts' => {
'Port' => '465',
'Hello' => 'mydomain.com',
},
'ssl' => 1,
'auth_user' => 'myuser',
'auth_pass' => 'mypass',
},
);
# run the kernel!
POE::Kernel->run();
ABSTRACT
This module is the companion to Test::Reporter::POEGateway and handles the task of actually mailing out reports. Typically you just spawn the module, select a mailer and let it do it's work.
DESCRIPTION
Really, all you have to do is load the module and call it's spawn() method:
use Test::Reporter::POEGateway::Mailer;
Test::Reporter::POEGateway::Mailer->spawn( ... );
This method will return failure on errors or return success. Normally you would select the mailer and set various options.
This constructor accepts either a hashref or a hash, valid options are:
alias
This sets the alias of the session.
The default is: POEGateway-Mailer
mailer
This sets the mailer subclass. The only one bundled with this distribution is Test::Reporter::POEGateway::Mailer::SMTP.
NOTE: This module automatically prepends "Test::Reporter::POEGateway::Mailer::" to the string.
The default is: SMTP
mailer_conf
This sets the configuration for the selected mailer. Please look at the POD for your selected mailer for what options is accepted.
NOTE: This needs to be a hashref!
The default is: {}
delay
This sets the delay in seconds between email sends. This is useful to "throttle" your emailer. Set to 0 to disable any delay.
The default is: 0
poegateway
If this option is present in the arguments, this module will receive reports directly from the Test::Reporter::POEGateway session. You cannot enable this option and use the reports argument below at the same time. If you enable this, this component will not use POE::Component::DirWatch and ignores any options for it.
The default is: undef ( not used )
use Test::Reporter::POEGateway;
use Test::Reporter::POEGateway::Mailer;
Test::Reporter::POEGateway->spawn(
'mailer' => 'mymailer',
);
Test::Reporter::POEGateway::Mailer->spawn(
'alias' => 'mymailer',
'poegateway' => 1,
'mailer' => 'SMTP',
'mailer_conf' => { ... },
);
reports
This sets the path where it will read received report submissions. Should be the same path you set in Test::Reporter::POEGateway.
NOTE: If this module fails to send a report due to various reasons, it will move the file to '$reports/fail' to avoid re-sending it over and over.
The default is: $ENV{HOME}/cpan_reports
dirwatch_alias
This sets the alias of the POE::Component::DirWatch session. Normally you don't need to touch the DirWatch session, but it is useful in certain situations. For example, if you wanted to pause the watcher or re-configure - all you need to do is to send events to this alias.
The default is: POEGateway-Mailer-DirWatch
dirwatch_interval
This sets the interval in seconds passed to POE::Component::DirWatch, please see the pod for more detail.
The default is: 120
host_aliases
This is a value-added change from Test::Reporter::HTTPGateway. This sets up a hash of ip => description. When the mailer sends a report, it will munge the report by adding a "fake" environment variable: SMOKER_HOST and put the description there if the sender ip matches. This is extremely useful if you have multiple smokers running and want to keep track of which smoker sent which report.
Here's a sample alias list: host_aliases => { '192.168.0.2' => 'my laptop', '192.168.0.5' => 'my smoke box', '192.168.0.7' => 'gentoo VM on smoke box', },
The default is: {}
maildone
This sets the event which will receive notifications when an email is sent or not. Receives one data structure in ARG0:
{
'STARTTIME' => 1260432932, # self-explanatory
'STOPTIME' => 1260432965, # self-explanatory
'STATUS' => 1, # boolean value for success
'MSGID' => '1260563289.Ca1bb50.15987@smoker-master', # will exist if status == 1
'ERROR' => 'SMTP AUTH failed', # will exist if status == 0
'DATA' => { # The report's data
'report' => 'TEXT OF REPORT',
'subject' => 'PASS Acme-LOLCAT-0.0.5 x86_64-linux 2.6.31-14-server',
'from' => 'apocal@cpan.org',
'via' => 'Test::Reporter 1.54, via CPANPLUS 0.88, via Test::Reporter::POEGateway 0.01',
'_sender' => '192.168.0.2',
'_host' => 'my laptop', # will exist if _sender matched a host alias
},
}
The default is: undef ( not enabled )
session
This sets the session which will receive the notification event. You can either use a POE session id, alias, or reference. You can just spawn the component inside another session and it will automatically receive the notifications.
The default is: undef ( caller session )
Commands
There is only a few command you can use, as this is a very simple module.
queue
Receives the email queue count. You need to call this via $poe_kernel->call( ... ) !
my $count = $_[KERNEL]->call( 'POEGateway-Mailer', 'queue' );
print "Number of pending emails in the queue: $count\n";
shutdown
Tells this module to shut down the underlying httpd session and terminate itself.
$_[KERNEL]->post( 'POEGateway-Mailer', 'shutdown' );
More Ideas
Additional mailers ( sendmail ), that's for sure. However, Test::Reporter::POEGateway::Mailer::SMTP fits the bill for me; I'm lazy now :)
EXPORT
None.
SEE ALSO
Test::Reporter::POEGateway::Mailer::SMTP
AUTHOR
Apocalypse <apocal@cpan.org>
COPYRIGHT AND LICENSE
Copyright 2010 by Apocalypse
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.