Improve sending of mailings.

This commit is contained in:
Martin Kamerbeek 2010-05-20 11:59:07 +02:00
parent e7dd066630
commit b7b1811387
3 changed files with 60 additions and 16 deletions

View file

@ -30,7 +30,7 @@ sub crud_definition {
},
status => {
fieldType => 'text',
defaultValue => 'queued', # Allowed are: 'queued', 'sent', 'error'
defaultValue => 'queued', # Allowed are: 'queued', 'sent', 'error', 'bounced'
},
errorMessage => {
fieldType => 'text',
@ -40,6 +40,12 @@ sub crud_definition {
fieldType => 'yesNo',
defaultValue => 1, # For safety: explicitly turn this off to send real emails
},
sendDate => {
fieldType => 'dateTime',
},
sentTo => {
fieldType => 'text',
},
);
$definition->{ properties } = {
@ -73,19 +79,16 @@ sub getQueuedTestEmails {
return $it;
}
sub getSendableEmails {
my $class = shift;
my $session = shift;
sub getQueued {
my $class = shift;
my $session = shift;
my $mailingId = shift;
my $it = $class->getAllIterator( $session, {
joinUsing => [
{ 'WGMailing' => 'mailingId' },
],
constraints => [
{ 'mailingId=?' => [ $mailingId ] },
{ 'isTest=?' => [ 0 ] },
{ 'status=?' => [ 'queued' ] },
{ 'state=?' => [ 'scheduled' ] },
{ 'sendDate <= ?' => [ time ] },
],
} );
@ -180,7 +183,11 @@ sub send {
$self->error( "Mail couldn't be sent by WebGUI::Mail::Send" );
}
else {
$self->update( { status => 'sent' } );
$self->update( {
status => 'sent',
sendDate => time,
sentTo => $to,
} );
}
return;