diff options
author | Matthew Somerville <matthew@mysociety.org> | 2014-07-14 16:09:42 +0100 |
---|---|---|
committer | Matthew Somerville <matthew@mysociety.org> | 2014-07-14 18:16:38 +0100 |
commit | 3b632b30d1cd3f66f3ac4635cf564c37a82135a4 (patch) | |
tree | 0cdf1653658a33c551ff8c44a76daa502db074ed | |
parent | 5e275809b6156c6eb6f1411fe4f22daa06bf55dc (diff) |
Add support for SMTP authentication and TLS.
Fixes #406. Include Perl modules necessary for Email::Send::SMTP to
handle TLS/SSL, and upgrade Dir::Self due to
https://rt.cpan.org/Public/Bug/Display.html?id=88393
-rw-r--r-- | conf/general.yml-example | 8 | ||||
-rw-r--r-- | cpanfile | 3 | ||||
-rw-r--r-- | cpanfile.snapshot | 51 | ||||
-rw-r--r-- | perllib/FixMyStreet/App/Model/EmailSend.pm | 21 |
4 files changed, 75 insertions, 8 deletions
diff --git a/conf/general.yml-example b/conf/general.yml-example index 0704fdb52..e98022052 100644 --- a/conf/general.yml-example +++ b/conf/general.yml-example @@ -156,9 +156,13 @@ RSS_LIMIT: '20' # How many reports to show per page on the All Reports pages ALL_REPORTS_PER_PAGE: 100 -# If you wish to send email through a SMTP server elsewhere, change this -# variable. +# If you wish to send email through a SMTP server elsewhere, change these +# variables. SMTP_TYPE should be one of '', 'ssl' or 'tls'. SMTP_SMARTHOST: 'localhost' +SMTP_TYPE: '' +SMTP_PORT: '' +SMTP_USERNAME: '' +SMTP_PASSWORD: '' # Gaze is a world-wide service for population density lookups. You can leave # this as is. @@ -18,6 +18,7 @@ requires 'Catalyst::Plugin::Unicode::Encoding'; requires 'Catalyst::View::TT'; # Modules used by FixMyStreet +requires 'Authen::SASL'; requires 'Cache::Memcached'; requires 'Carp'; requires 'CGI'; @@ -61,6 +62,8 @@ requires 'Module::Pluggable'; requires 'Moose'; requires 'namespace::autoclean'; requires 'Net::Domain::TLD'; +requires 'Net::SMTP::SSL'; +requires 'Net::SMTP::TLS'; requires 'Path::Class'; requires 'POSIX'; requires 'Readonly'; diff --git a/cpanfile.snapshot b/cpanfile.snapshot index d64ba4c63..203583518 100644 --- a/cpanfile.snapshot +++ b/cpanfile.snapshot @@ -28,6 +28,27 @@ DISTRIBUTIONS requirements: ExtUtils::MakeMaker 0 Test::More 0 + Authen-SASL-2.16 + pathname: G/GB/GBARR/Authen-SASL-2.16.tar.gz + provides: + Authen::SASL 2.16 + Authen::SASL::CRAM_MD5 2.14 + Authen::SASL::EXTERNAL 2.14 + Authen::SASL::Perl 2.14 + Authen::SASL::Perl::ANONYMOUS 2.14 + Authen::SASL::Perl::CRAM_MD5 2.14 + Authen::SASL::Perl::DIGEST_MD5 2.14 + Authen::SASL::Perl::EXTERNAL 2.14 + Authen::SASL::Perl::GSSAPI 0.05 + Authen::SASL::Perl::LOGIN 2.14 + Authen::SASL::Perl::Layer 2.14 + Authen::SASL::Perl::PLAIN 2.14 + requirements: + Digest::HMAC_MD5 0 + Digest::MD5 0 + ExtUtils::MakeMaker 6.42 + Test::More 0 + perl 5.005 B-Hooks-EndOfScope-0.12 pathname: B/BO/BOBTFISH/B-Hooks-EndOfScope-0.12.tar.gz provides: @@ -2398,15 +2419,14 @@ DISTRIBUTIONS Digest::SHA 1 ExtUtils::MakeMaker 0 perl 5.004 - Dir-Self-0.10 - pathname: M/MA/MAUKE/Dir-Self-0.10.tar.gz + Dir-Self-0.11 + pathname: M/MA/MAUKE/Dir-Self-0.11.tar.gz provides: - Dir::Self undef + Dir::Self 0.11 requirements: Carp 0 - ExtUtils::MakeMaker 0 File::Spec 0 - Test::More 0 + strict 0 Dist-CheckConflicts-0.09 pathname: D/DO/DOY/Dist-CheckConflicts-0.09.tar.gz provides: @@ -4200,6 +4220,27 @@ DISTRIBUTIONS IO::Select 0 IO::Socket::INET 0 perl 5.006002 + Net-SMTP-SSL-1.01 + pathname: C/CW/CWEST/Net-SMTP-SSL-1.01.tar.gz + provides: + Net::SMTP::SSL 1.01 + requirements: + ExtUtils::MakeMaker 0 + IO::Socket::SSL 0 + Net::SMTP 0 + Test::More 0.47 + Net-SMTP-TLS-0.12 + pathname: A/AW/AWESTHOLM/Net-SMTP-TLS-0.12.tar.gz + provides: + Net::SMTP::TLS 0.12 + requirements: + Digest::HMAC_MD5 0 + ExtUtils::MakeMaker 0 + IO::Socket::INET 0 + IO::Socket::SSL 0 + MIME::Base64 0 + Net::SSLeay 0 + Test::More 0 Net-SSLeay-1.52 pathname: M/MI/MIKEM/Net-SSLeay-1.52.tar.gz provides: diff --git a/perllib/FixMyStreet/App/Model/EmailSend.pm b/perllib/FixMyStreet/App/Model/EmailSend.pm index 761856bde..7f130c26d 100644 --- a/perllib/FixMyStreet/App/Model/EmailSend.pm +++ b/perllib/FixMyStreet/App/Model/EmailSend.pm @@ -34,9 +34,28 @@ if ( FixMyStreet->test_mode ) { elsif ( my $smtp_host = FixMyStreet->config('SMTP_SMARTHOST') ) { # Email::Send::SMTP + my $type = FixMyStreet->config('SMTP_TYPE') || ''; + my $port = FixMyStreet->config('SMTP_PORT') || ''; + my $username = FixMyStreet->config('SMTP_USERNAME') || ''; + my $password = FixMyStreet->config('SMTP_PASSWORD') || ''; + + unless ($port) { + $port = 25; + $port = 465 if $type eq 'ssl'; + $port = 587 if $type eq 'tls'; + } + + my $mailer_args = [ + Host => $smtp_host, + Port => $port, + ]; + push @$mailer_args, ssl => 1 if $type eq 'ssl'; + push @$mailer_args, tls => 1 if $type eq 'tls'; + push @$mailer_args, username => $username, password => $password + if $username && $password; $args = { mailer => 'FixMyStreet::EmailSend', - mailer_args => [ Host => $smtp_host ], + mailer_args => $mailer_args, }; } else { |