"Fossies" - the Fresh Open Source Software Archive

Member "formmail_modules-3.14m1/lib/CGI/NMS/Mailer/Sendmail.pm" (11 Aug 2004, 2382 Bytes) of package /linux/www/old/formmail_modules-3.14m1.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Perl source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "Sendmail.pm" see the Fossies "Dox" file reference documentation.

    1 package CGI::NMS::Mailer::Sendmail;
    2 use strict;
    3 
    4 use IO::File;
    5 use CGI::NMS::Mailer;
    6 use base qw(CGI::NMS::Mailer);
    7 
    8 =head1 NAME
    9 
   10 CGI::NMS::Mailer::Sendmail - mail sender using sendmail
   11 
   12 =head1 SYNOPSYS
   13 
   14   my $mailer = CGI::NMS::Mailer::Sendmail->new('/usr/lib/sendmail -oi -t');
   15 
   16   $mailer->newmail($from, $to);
   17   $mailer->print($email_header_and_body);
   18   $mailer->endmail;
   19 
   20 =head1 DESCRIPTION
   21 
   22 This implementation of the mailer object defined in L<CGI::NMS::Mailer>
   23 uses a piped open to the UNIX sendmail program to send the email.
   24 
   25 =head1 CONSTRUCTORS
   26 
   27 =over
   28 
   29 =item new ( MAILPROG )
   30 
   31 MAILPROG must be the shell command to which a pipe is opened, including
   32 all nessessary switches to cause the sendmail program to read the email
   33 recipients from the header of the email.
   34 
   35 =cut
   36 
   37 sub new {
   38   my ($pkg, $mailprog) = @_;
   39 
   40   return bless { Mailprog => $mailprog }, $pkg;
   41 }
   42 
   43 =back
   44 
   45 =head1 METHODS
   46 
   47 See L<CGI::NMS::Mailer> for the user interface to these methods.
   48 
   49 =over
   50 
   51 =item newmail ( SCRIPTNAME, POSTMASTER, @RECIPIENTS )
   52 
   53 Opens the sendmail pipe and outputs trace headers.
   54 
   55 =cut
   56 
   57 sub newmail {
   58   my ($self, $scriptname, $postmaster, @recipients) = @_;
   59 
   60   my $command = $self->{Mailprog};
   61   $command .= qq{ -f "$postmaster"} if $postmaster;
   62   my $pipe;
   63   eval { local $SIG{__DIE__};
   64          $pipe = IO::File->new("| $command");
   65        };
   66   if ($@) {
   67     die $@ unless $@ =~ /Insecure directory/;
   68     delete $ENV{PATH};
   69     $pipe = IO::File->new("| $command");
   70   }
   71 
   72   die "Can't open mailprog [$command]\n" unless $pipe;
   73   $self->{Pipe} = $pipe;
   74 
   75   $self->output_trace_headers($scriptname);
   76 }
   77 
   78 =item print ( @ARGS )
   79 
   80 Writes some email body to the sendmail pipe.
   81 
   82 =cut
   83 
   84 sub print {
   85   my ($self, @args) = @_;
   86 
   87   $self->{Pipe}->print(@args) or die "write to sendmail pipe: $!";
   88 }
   89 
   90 =item endmail ()
   91 
   92 Closes the sendmail pipe.
   93 
   94 =cut
   95 
   96 sub endmail {
   97   my ($self) = @_;
   98 
   99   $self->{Pipe}->close or die "close sendmail pipe failed, mailprog=[$self->{Mailprog}]";
  100   delete $self->{Pipe};
  101 }
  102 
  103 =back
  104 
  105 =head1 MAINTAINERS
  106 
  107 The NMS project, E<lt>http://nms-cgi.sourceforge.net/E<gt>
  108 
  109 To request support or report bugs, please email
  110 E<lt>nms-cgi-support@lists.sourceforge.netE<gt>
  111 
  112 =head1 COPYRIGHT
  113 
  114 Copyright 2003 London Perl Mongers, All rights reserved
  115 
  116 =head1 LICENSE
  117 
  118 This module is free software; you are free to redistribute it
  119 and/or modify it under the same terms as Perl itself.
  120 
  121 =cut
  122 
  123 1;
  124