home *** CD-ROM | disk | FTP | other *** search
/ PC Professionell 2004 December / PCpro_2004_12.ISO / files / webserver / xampp / xampp-perl-addon-1.4.9-installer.exe / smtpsend.al < prev    next >
Encoding:
Text File  |  2004-03-29  |  1.9 KB  |  84 lines

  1. # NOTE: Derived from blib\lib\Mail/Internet.pm.
  2. # Changes made here will be lost when autosplit is run again.
  3. # See AutoSplit.pm.
  4. package Mail::Internet;
  5.  
  6. #line 560 "blib\lib\Mail/Internet.pm (autosplit into blib\lib\auto\Mail\Internet\smtpsend.al)"
  7. sub smtpsend;
  8.  
  9. use Carp;
  10. use Mail::Util qw(mailaddress);
  11. use Mail::Address;
  12. use Net::Domain qw(hostname);
  13. use Net::SMTP;
  14. use strict;
  15.  
  16.  sub smtpsend 
  17. {
  18.     my $src  = shift;
  19.     my %opt = @_;
  20.     my $host = $opt{Host};
  21.     my $envelope = $opt{MailFrom} || mailaddress();
  22.     my $noquit = 0;
  23.     my $smtp;
  24.     my @hello = defined $opt{Hello} ? (Hello => $opt{Hello}) : ();
  25.  
  26.     push(@hello, 'Port', $opt{'Port'})
  27.     if exists $opt{'Port'};
  28.  
  29.     push(@hello, 'Debug', $opt{'Debug'})
  30.     if exists $opt{'Debug'};
  31.  
  32.     unless(defined($host)) {
  33.     local $SIG{__DIE__};
  34.     my @hosts = qw(mailhost localhost);
  35.     unshift(@hosts, split(/:/, $ENV{SMTPHOSTS})) if(defined $ENV{SMTPHOSTS});
  36.  
  37.     foreach $host (@hosts) {
  38.         $smtp = eval { Net::SMTP->new($host, @hello) };
  39.         last if(defined $smtp);
  40.     }
  41.     }
  42.     elsif(ref($host) && UNIVERSAL::isa($host,'Net::SMTP')) {
  43.     $smtp = $host;
  44.     $noquit = 1;
  45.     }
  46.     else {
  47.     local $SIG{__DIE__};
  48.     $smtp = eval { Net::SMTP->new($host, @hello) };
  49.     }
  50.  
  51.     return ()
  52.     unless(defined $smtp);
  53.  
  54.     my $hdr = $src->head->dup;
  55.  
  56.     _prephdr($hdr);
  57.  
  58.     # Who is it to
  59.  
  60.     my @rcpt = map { ref($_) ? @$_ : $_ } grep { defined } @opt{'To','Cc','Bcc'};
  61.     @rcpt = map { $hdr->get($_) } qw(To Cc Bcc)
  62.     unless @rcpt;
  63.     my @addr = map($_->address, Mail::Address->parse(@rcpt));
  64.  
  65.     return ()
  66.     unless(@addr);
  67.  
  68.     $hdr->delete('Bcc'); # Remove blind Cc's
  69.  
  70.     # Send it
  71.  
  72.     my $ok = $smtp->mail( $envelope ) &&
  73.         $smtp->to(@addr) &&
  74.         $smtp->data(join("", @{$hdr->header},"\n",@{$src->body}));
  75.  
  76.     $smtp->quit
  77.     unless $noquit;
  78.  
  79.     $ok ? @addr : ();
  80. }
  81.  
  82. # end of Mail::Internet::smtpsend
  83. 1;
  84.