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 /perllib/FixMyStreet/App/Model | |
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
Diffstat (limited to 'perllib/FixMyStreet/App/Model')
-rw-r--r-- | perllib/FixMyStreet/App/Model/EmailSend.pm | 21 |
1 files changed, 20 insertions, 1 deletions
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 { |