]> mj.ucw.cz Git - pciids.git/blob - PciIds/Email.pm
Output what the sub-item really is
[pciids.git] / PciIds / Email.pm
1 package PciIds::Email;
2 use strict;
3 use warnings;
4 use PciIds::Config;
5 use PciIds::Users;
6 use base 'Exporter';
7
8 our @EXPORT = qw(&sendMail);
9
10 checkConf( [ 'from_addr', 'sendmail' ] );
11 defConf( { 'sendmail' => '/usr/sbin/sendmail' } );
12
13 sub sendMail( $$$ ) {
14         my( $to, $subject, $body ) = @_;
15         my( $from, $sendmail ) = confList( [ 'from_addr', 'sendmail' ] );
16         my $error;
17         ( $error, $to ) = emailCheck( $to, undef );
18         die "Invalid email in database $to\n" if defined $error;
19         $body =~ s/^\.$/../gm;
20         open SENDMAIL, "|$sendmail -f$from $to" or die 'Can not send mail';
21         print SENDMAIL "From: $from\n".
22                 "To: $to\n".
23                 "Subject: $subject\n".
24                 "Content-Type: text/plain; charset=\"utf8\"\n".
25                 "\n".
26                 $body."\n.\n";
27         close SENDMAIL or die "Sending mail failed: $!, $?";
28 }
29
30 1;