Skip to content
Snippets Groups Projects
Commit 763fb58f authored by Guillaume ROUSSE's avatar Guillaume ROUSSE
Browse files

inline mail sending function

parent aabfc388
No related branches found
No related tags found
No related merge requests found
......@@ -104,30 +104,6 @@ sub update_ssp_authsources {
}
## Send a mail notice
## Default is to send email to the manager admins, unless other recipients are specified
## mail_notice(IN)
## IN is a HASH with expected entries :
## template : mail template file
## data : data used by the TT2 parser
sub mail_notice {
my (%args) = @_;
die "unable to send mail, no sendmail executable found"
unless -x '/usr/sbin/sendmail';
open SENDMAIL,
"|/usr/sbin/sendmail -f $args{data}->{from} $args{data}->{to}";
my $tt2 = Template->new({
INCLUDE_PATH => $args{templates_dir}
});
$tt2->process($args{template}, $args{data}, \*SENDMAIL)
or die $tt2->error();
close SENDMAIL;
}
1;
__END__
......
......@@ -362,34 +362,43 @@ sub req_generate_token {
$self->{out}->{sp_entityid} = $self->{in}->{sp_entityid};
$self->{out}->{subtitle} = 'Generate an authentication token';
## Send the challenge email with the token
eval {
IdPAccountManager::Tools::mail_notice(
template => 'mail/send_authentication_token.tt2.eml',
templates_dir => $self->{configuration}->{templates_dir},
data => {
env => {
REMOTE_HOST => $ENV{REMOTE_HOST},
REMOTE_ADDR => $ENV{REMOTE_ADDR},
},
conf => {
app_name => $self->{configuration}->{app_name},
app_url => $self->{configuration}->{app_url},
support_email => $self->{configuration}->{support_email},
},
from => $self->{configuration}->{notice_from},
to => $self->{in}->{email_address},
sp_entityid => $self->{in}->{sp_entityid},
authentication_token => $token->token(),
}
);
my $sender = $self->{configuration}->{notice_from};
my $recipient = $self->{in}->{email_address};
unless (open(SENDMAIL, "|/usr/sbin/sendmail -f $sender $recipient")) {
push @{ $self->{out}->{errors} }, "mail_notification_error";
$self->{logger}->errorf("Mail notification error: %s", $ERRNO);
return undef;
}
my $tt2 = Template->new({
INCLUDE_PATH => $self->{configuration}->{templates_dir}
});
my $template = 'mail/send_authentication_token.tt2.eml';
my $data = {
env => {
REMOTE_HOST => $ENV{REMOTE_HOST},
REMOTE_ADDR => $ENV{REMOTE_ADDR},
},
conf => {
app_name => $self->{configuration}->{app_name},
app_url => $self->{configuration}->{app_url},
support_email => $self->{configuration}->{support_email},
},
from => $sender,
to => $recipient,
sp_entityid => $self->{in}->{sp_entityid},
authentication_token => $token->token(),
};
if ($EVAL_ERROR) {
unless ($tt2->process($template, $data, \*SENDMAIL)) {
push @{ $self->{out}->{errors} }, "mail_notification_error";
$self->{logger}->errorf("Mail notification error: %s", $EVAL_ERROR);
return undef;
}
close SENDMAIL;
$self->{logger}->infof(
"Token send to %s for sp_entityid=%s;token=%s",
$self->{in}->{email_address},
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment