aboutsummaryrefslogtreecommitdiffstats
path: root/perllib/FixMyStreet/SendReport/Email.pm
diff options
context:
space:
mode:
authorMatthew Somerville <matthew@mysociety.org>2015-01-09 22:55:08 +0000
committerMatthew Somerville <matthew@mysociety.org>2015-01-13 16:28:50 +0000
commit676181084d88b0ec94d42521162b4571cb0c0552 (patch)
tree744979e676295aa7daf2de3aa03818b1f6419fb6 /perllib/FixMyStreet/SendReport/Email.pm
parent4ae8d597a80d91084dcdcd999d480f41a57c70d1 (diff)
Use same handling for cron and non-cron email.
This means that e.g. SMTP authentication is used when set up by all emails, not just non-cron ones. Fixes #988.
Diffstat (limited to 'perllib/FixMyStreet/SendReport/Email.pm')
-rw-r--r--perllib/FixMyStreet/SendReport/Email.pm32
1 files changed, 15 insertions, 17 deletions
diff --git a/perllib/FixMyStreet/SendReport/Email.pm b/perllib/FixMyStreet/SendReport/Email.pm
index 19c6405d2..797b41e91 100644
--- a/perllib/FixMyStreet/SendReport/Email.pm
+++ b/perllib/FixMyStreet/SendReport/Email.pm
@@ -4,11 +4,8 @@ use Moose;
BEGIN { extends 'FixMyStreet::SendReport'; }
-use mySociety::EmailUtil;
-
sub build_recipient_list {
my ( $self, $row, $h ) = @_;
- my %recips;
my $all_confirmed = 1;
foreach my $body ( @{ $self->bodies } ) {
@@ -49,12 +46,10 @@ sub build_recipient_list {
}
for my $email ( @emails ) {
push @{ $self->to }, [ $email, $body_name ];
- $recips{$email} = 1;
}
}
- return () unless $all_confirmed;
- return keys %recips;
+ return $all_confirmed && @{$self->to};
}
sub get_template {
@@ -76,34 +71,36 @@ sub send {
my $self = shift;
my ( $row, $h ) = @_;
- my @recips = $self->build_recipient_list( $row, $h );
+ my $recips = $self->build_recipient_list( $row, $h );
# on a staging server send emails to ourselves rather than the bodies
if (mySociety::Config::get('STAGING_SITE') && !mySociety::Config::get('SEND_REPORTS_ON_STAGING') && !FixMyStreet->test_mode) {
- @recips = ( $row->user->email );
+ $recips = 1;
+ @{$self->to} = [ $row->user->email, $self->to->[0][1] || $row->name ];
}
- unless ( @recips ) {
+ unless ($recips) {
$self->error( 'No recipients' );
return 1;
}
my ($verbose, $nomail) = CronFns::options();
my $cobrand = FixMyStreet::Cobrand->get_class_for_moniker($row->cobrand)->new();
+ my $params = {
+ _template_ => $self->get_template( $row ),
+ _parameters_ => $h,
+ To => $self->to,
+ From => $self->send_from( $row ),
+ };
+ $params->{Bcc} = $self->bcc if @{$self->bcc};
my $result = FixMyStreet::App->send_email_cron(
- {
- _template_ => $self->get_template( $row ),
- _parameters_ => $h,
- To => $self->to,
- From => $self->send_from( $row ),
- },
+ $params,
mySociety::Config::get('CONTACT_EMAIL'),
- \@recips,
$nomail,
$cobrand
);
- if ( $result == mySociety::EmailUtil::EMAIL_SUCCESS ) {
+ unless ($result) {
$self->success(1);
} else {
$self->error( 'Failed to send email' );
@@ -143,4 +140,5 @@ sub _get_district_for_contact {
($district) = keys %$district;
return $district;
}
+
1;