Add basic infrastructure to actually send out mailings.
This commit is contained in:
parent
3f3ee717b7
commit
80c1ce0b44
4 changed files with 99 additions and 5 deletions
|
|
@ -48,5 +48,88 @@ sub crud_definition {
|
|||
return $definition;
|
||||
}
|
||||
|
||||
sub getMailing {
|
||||
my $self = shift;
|
||||
my $session = $self->session;
|
||||
|
||||
my $mailing = WebGUI::Mailing->new( $session, $self->get('mailingId') );
|
||||
#### TODO: error checking;
|
||||
return $mailing;
|
||||
}
|
||||
|
||||
sub getQueuedTestEmails {
|
||||
my $class = shift;
|
||||
my $session = shift;
|
||||
|
||||
my $it = $class->getAllIterator( $session, {
|
||||
constraints => [
|
||||
{ 'isTest=?' => [ 1 ] },
|
||||
{ 'status=?' => [ 'queued' ] },
|
||||
],
|
||||
} );
|
||||
|
||||
return $it;
|
||||
}
|
||||
|
||||
sub error {
|
||||
my $self = shift;
|
||||
my $message = shift;
|
||||
|
||||
$self->update( {
|
||||
status => 'error',
|
||||
errorMessage => $message || 'No error message available',
|
||||
} );
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
sub send {
|
||||
my $self = shift;
|
||||
my $session = $self->session;
|
||||
|
||||
#### TODO: Error checking
|
||||
my $mailing = $self->getMailing;
|
||||
my $body = $mailing->getAsset->processContentAsUser( $mailing->get('issueId'), $self->get('userId') );
|
||||
|
||||
# Mail is a test mail but there is noone to send the result to
|
||||
if ( $self->get( 'isTest' ) && !$self->get('recipientEmail') ) {
|
||||
$self->error( 'Cannot send test mails without an override reciepint address' );
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
# Determine recipients email address and bail out if we can't find one.
|
||||
my $to = $self->get('recipientEmail') || $self->user->get('email');
|
||||
if ( !$to ) {
|
||||
$self->error( 'Cannot find an email address for this user' );
|
||||
return;
|
||||
}
|
||||
|
||||
# Fetch subject
|
||||
my $subject = '[TEST] Subject selection still needs to be implemented.';
|
||||
|
||||
# Setup email
|
||||
my $mail = WebGUI::Mail::Send->create( $session, {
|
||||
#from => TODO
|
||||
to => $to,
|
||||
subject => $subject,
|
||||
} );
|
||||
$mail->addHtml( $body );
|
||||
|
||||
# And send it.
|
||||
my $success = $mail->send;
|
||||
|
||||
|
||||
if ( $success ne '1' ) {
|
||||
$self->error( "Mail couldn't be sent by WebGUI::Mail::Send" );
|
||||
}
|
||||
else {
|
||||
$self->update( { status => 'sent' } );
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
1;
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue