Test::Nightly::Email - Emails reports, errors etc.


Test-Nightly documentation Contained in the Test-Nightly distribution.

Index


Code Index:

NAME

Top

Test::Nightly::Email - Emails reports, errors etc.

DESCRIPTION

Top

Package that uses the Email::* modules to mail reports and error notifications. Use this module to set up your email configuration. You probably should not be dealing with this directly.

SYNOPSIS

Top

  my $email = Test::Nightly::Email->new({
    to => 'kirstinbettiol@gmail.com',
  });

  $email->send({
    subject => 'Your Test Report',
    message => 'All your tests failed!'
  });

new()

  my $email = Test::Nightly::Email->new({
    to           => 'kirstinbettiol@gmail.com',  # Required
    cc           => 'kirstinbettiol@gmail.com',
    bcc          => 'kirstinbettiol@gmail.com',
    from         => 'kirstinbettiol@gmail.com',
    subject      => 'The results of your test',
    content_type => 'text/html',                 # Defaults 'text/html' 
    mailer       => 'Sendmail',                  # 'SMTP' || 'Qmail'. Defaults to 'Sendmail'
    message      => 'The body of the email',
    smtp_server  => 'smtp.yourserver.com',       # Required if you specify SMTP as your mailer.
  });

The constructor to create the new email object.

send()

  $email->send({
    ... takes the same arguments as new ...
  });

Sends the email.

List of methods:

Top

to

The email "To" field. Takes a comma separated list of emails. Required.

cc

The email "Cc" field. Takes a comma separated list of emails.

bcc

The email "Bcc" field. Takes a comma separated list of emails.

from

The email "from" field.

subject

The subject line of the email

content_type

The Content-type you wish the email to be. Defaults to 'text/html'.

mailer

The mailer you wish to use. Currently supports 'Sendmail' || 'SMTP' || 'Qmail'. Defaults to 'Sendmail'

message

The body of the email.

smtp_server

If you specify SMTP as your mailer then you are required to specify this.

AUTHOR

Top

Kirstin Bettiol <kirstinbettiol@gmail.com>

COPYRIGHT

Top

SEE ALSO

Top

Email::Send, Email::Simple, Email::Simple::Creator, Email::Send::Qmail, Email::Send::SMTP, Email::Send::Sendmail, Test::Nightly, Test::Nightly::Test, Test::Nightly::Report, Test::Nightly::Email, perl.


Test-Nightly documentation Contained in the Test-Nightly distribution.
package Test::Nightly::Email;

use strict;
use warnings;

use Carp;
use Email::Send;
use Email::Simple;
use Email::Simple::Creator;

use base qw(Test::Nightly::Base Class::Accessor::Fast);

my @methods = qw(
	smtp_server
	to           
	cc           
	bcc          
	from         
	subject      
	content_type 
	mailer       
	message      
	smtp_server
);

__PACKAGE__->mk_accessors(@methods);

our $VERSION = '0.03';

sub new {

    my ($class, $conf) = @_;

	my $self = bless {}, $class;

	$self->_init($conf, \@methods);

	return $self;

}

sub email {

    my ($self, $conf) = @_;

	$self->_init($conf, \@methods);
	
	$self->content_type('text/html') 	unless defined $self->content_type();
	$self->mailer('Sendmail')		 	unless defined $self->mailer();

	unless (defined $self->to()) {
		return;
	}

	my %header = (
		'To'           => $self->to(),
		'Cc'           => $self->cc(),
		'Bcc'          => $self->bcc(),
		'From'         => $self->from(),
		'Subject'      => $self->subject(),
		'Content-Type' => $self->content_type(),
	);

	my $email = Email::Simple->create(
		header => [%header],
		body   => $self->message(),
	);

	if ($self->mailer() =~ /Sendmail/i) {

		send Sendmail => $email;

	} elsif ($self->mailer() =~ /SMTP/i) {

		if (defined $self->smtp_server()) {

			send SMTP => $email, $self->smtp_server();

		} 

	} elsif ($self->mailer() =~ /Qmail/i) {

		send Qmail => $email;

	}

}

1;