Skip to content

Commit

Permalink
Add a generic mailing function under site-admin/send-email
Browse files Browse the repository at this point in the history
  • Loading branch information
melmothx committed Dec 16, 2023
1 parent 405f70f commit 20185a5
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 0 deletions.
1 change: 1 addition & 0 deletions cpanfile
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ requires 'Email::MIME::Kit' => '3';
requires 'Email::MIME::Kit::Renderer::TT' => '1.001';
requires 'Email::Address' => '1.910';
requires 'Authen::SASL';
requires 'Email::Stuffer';

requires 'HTTP::Tiny';
requires 'Crypt::XkcdPassword';
Expand Down
2 changes: 2 additions & 0 deletions debian/control
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ Build-Depends-Indep: libbytes-random-secure-perl,
libemail-mime-kit-perl,
libemail-mime-kit-renderer-tt-perl,
libemail-sender-perl,
libemail-stuffer-perl,
libauthen-sasl-perl,
libemail-valid-perl,
libemail-address-perl,
Expand Down Expand Up @@ -145,6 +146,7 @@ Depends: ${misc:Depends}, ${perl:Depends},
libemail-mime-kit-perl,
libemail-mime-kit-renderer-tt-perl,
libemail-sender-perl,
libemail-stuffer-perl,
libauthen-sasl-perl,
libemail-valid-perl,
libemail-address-perl,
Expand Down
27 changes: 27 additions & 0 deletions lib/AmuseWikiFarm/Controller/SiteAdmin.pm
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use namespace::autoclean;
BEGIN { extends 'Catalyst::Controller'; }

use AmuseWikiFarm::Log::Contextual;
use Email::Stuffer;

=head1 NAME
Expand Down Expand Up @@ -92,6 +93,32 @@ sub delete_user :Chained('users') :PathPart('delete') :Args(1) {
$c->response->redirect($c->uri_for_action('/siteadmin/show_users'));
}

sub send_email :Chained('root') :PathPart('send-email') :Args(0) {
my ($self, $c) = @_;
my $params = $c->request->body_params;
my $site = $c->stash->{site};
if ($params->{subject} and $params->{text_body} and $params->{to}) {
my %args = (
from => $site->mail_from_default,
to => $params->{to},
text_body => $params->{text_body},
subject => $params->{subject}
);
foreach my $f (qw/cc bcc reply_to/) {
if (my $v = $params->{$f}) {
$args{$f} = $v;
}
}
Dlog_info { "Sending mail with $_" } \%args;
if (Email::Stuffer->new(\%args)->send) {
$c->flash(status_msg => "E-mail sent!");
}
else {
$c->flash(error_msg => "Failure sending e-mail");
}
}
}

=encoding utf8
=head1 AUTHOR
Expand Down

0 comments on commit 20185a5

Please sign in to comment.