4 use vars qw ( @ISA @EXPORT_OK );
8 @EXPORT_OK = qw( send_email );
12 FS::Misc - Miscellaneous subroutines
16 use FS::Misc qw(send_email);
22 Miscellaneous subroutines. This module contains miscellaneous subroutines
23 called from multiple other modules. These are not OO or necessarily related,
24 but are collected here to elimiate code duplication.
30 =item send_email OPTION => VALUE ...
36 I<to> - (required) comma-separated scalar or arrayref of recipients
38 I<subject> - (required)
40 I<content-type> - (optional) MIME type
42 I<body> - (required) arrayref of body text lines
49 use Mail::Internet 1.44;
52 FS::UID->install_callback( sub {
59 $ENV{MAILADDRESS} = $options{'from'};
60 my $to = ref($options{to}) ? join(', ', @{ $options{to} } ) : $options{to};
62 'From: '. $options{'from'},
64 'Sender: '. $options{'from'},
65 'Reply-To: '. $options{'from'},
66 'Date: '. time2str("%a, %d %b %Y %X %z", time),
67 'Subject: '. $options{'subject'},
69 push @header, 'Content-Type: '. $options{'content-type'}
70 if exists($options{'content-type'});
71 my $header = new Mail::Header ( \@header );
73 my $message = new Mail::Internet (
75 'Body' => $options{'body'},
78 my $smtpmachine = $conf->config('smtpmachine');
81 my $rv = $message->smtpsend( 'Host' => $smtpmachine )
82 or $message->smtpsend( Host => $smtpmachine, Debug => 1 );
84 if ($rv) { #smtpsend returns a list of addresses, not true/false
87 return "can't send email to $to via server $smtpmachine with SMTP: $!";
98 L<FS::UID>, L<FS::CGI>, L<FS::Record>, the base documentation.