diff options
author | Edmund von der Burg <evdb@mysociety.org> | 2011-03-02 13:55:37 +0000 |
---|---|---|
committer | Edmund von der Burg <evdb@mysociety.org> | 2011-03-02 13:55:37 +0000 |
commit | 90395716d892de1d1134a7d0e68866e699c19406 (patch) | |
tree | 9fe5e0b1247ad1f6c0da774ea17fc225667b87b8 /perllib/FixMyStreet/App/Model/EmailSend.pm | |
parent | c5a4a6e496f4aebd496336c44a61c0b1c64dfccd (diff) |
Simple email sending
Diffstat (limited to 'perllib/FixMyStreet/App/Model/EmailSend.pm')
-rw-r--r-- | perllib/FixMyStreet/App/Model/EmailSend.pm | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/perllib/FixMyStreet/App/Model/EmailSend.pm b/perllib/FixMyStreet/App/Model/EmailSend.pm new file mode 100644 index 000000000..de85857f7 --- /dev/null +++ b/perllib/FixMyStreet/App/Model/EmailSend.pm @@ -0,0 +1,51 @@ +package FixMyStreet::App::Model::EmailSend; +use base 'Catalyst::Model::Adaptor'; + +use strict; +use warnings; + +use FixMyStreet; +use Email::Send; + +=head1 NAME + +FixMyStreet::App::Model::EmailSend + +=head1 DESCRIPTION + +Thin wrapper around Email::Send - configuring it correctly acording to our config. + +If the config value 'SMTP_SMARTHOST' is set then email is routed via SMTP to +that. Otherwise it is sent using a 'sendmail' like binary on the local system. + +And finally if if FixMyStreet->test_mode returns true then emails are not sent +at all but are stored in memory for the test suite to inspect (using +Email::Send::Test). + +=cut + +my $args = undef; + +if ( FixMyStreet->test_mode ) { + + # Email::Send::Test + $args = { mailer => 'Test', }; +} +elsif ( my $smtp_host = FixMyStreet->config('SMTP_SMARTHOST') ) { + + # Email::Send::SMTP + $args = { + mailer => 'SMTP', + mailer_args => { Host => $smtp_host }, + }; +} +else { + + # Email::Send::Sendmail + $args = { mailer => 'Sendmail' }; +} + +__PACKAGE__->config( + class => 'Email::Send', + args => $args, +); |