]> mj.ucw.cz Git - pciids.git/blob - PciIds/Email.pm
Revert "Reorder columns in admin form"
[pciids.git] / PciIds / Email.pm
1 #       PciIds web database
2 #       Copyright (C) 2008 Michal Vaner (vorner@ucw.cz)
3 #
4 #       This program is free software; you can redistribute it and/or modify
5 #       it under the terms of the GNU General Public License as published by
6 #       he Free Software Foundation; either version 2 of the License, or
7 #       (at your option) any later version.
8 #
9 #       This program is distributed in the hope that it will be useful,
10 #       but WITHOUT ANY WARRANTY; without even the implied warranty of
11 #       MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12 #
13 #       GNU General Public License for more details.
14 #
15 #       You should have received a copy of the GNU General Public License
16 #       along with this program; if not, write to the Free Software
17 #       Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
18
19 package PciIds::Email;
20 use strict;
21 use warnings;
22 use PciIds::Config;
23 use PciIds::Users;
24 use base 'Exporter';
25
26 our @EXPORT = qw(&sendMail);
27
28 checkConf( [ 'from_addr', 'sendmail' ] );
29 defConf( { 'sendmail' => '/usr/sbin/sendmail' } );
30
31 sub sendMail( $$$ ) {
32         my( $to, $subject, $body ) = @_;
33         my( $from, $sendmail ) = confList( [ 'from_addr', 'sendmail' ] );
34         my $error;
35         ( $error, $to ) = emailCheck( $to, undef );
36         die "Invalid email in database $to\n" if defined $error;
37         $body =~ s/^\.$/../gm;
38         $ENV{'PATH'} = '/usr/sbin';
39         open SENDMAIL, "|$sendmail -f'$from' '$to'" or die 'Can not send mail';
40         print SENDMAIL "From: $from\n".
41                 "To: $to\n".
42                 "Subject: $subject\n".
43                 "Content-Type: text/plain; charset=\"utf8\"\n".
44                 "\n".
45                 $body."\n.\n";
46         close SENDMAIL or die "Sending mail failed: $!, $?";
47 }
48
49 1;