home *** CD-ROM | disk | FTP | other *** search
/ io Programmo 27 / IOPROG_27.ISO / SOFT / PERLPAD3.ZIP / PERLPAD3.CAB / mail-lib.ppm < prev    next >
Encoding:
Text File  |  1999-02-06  |  1.2 KB  |  57 lines

  1.  Sends email by using the SMTP Server
  2. Viotix Incoporated
  3.  
  4. sub send_mail{
  5.   my ($from, $to, $subject, $body) = @_;
  6.  
  7.   use Net::SMTP;
  8.  
  9.     # set to 1 to enable debug mode
  10.   my $debug = 0;
  11.  
  12.     # get the recipients for smtp to identify
  13.   my $smtp_from = $from;
  14.   my $smtp_to   = $to;
  15.  
  16.     # build the mail message
  17.   my $mail_message = <<__END_OF_MAIL__;
  18. To: $to
  19. From: $from
  20. Subject: $subject
  21.  
  22. $body
  23.  
  24. __END_OF_MAIL__
  25.  
  26.     # Set this parameter if you don't have a valid Net/Config.pm entry for SMTP host
  27.     # and uncomment it in the Net::SMTP->new call
  28.     # my $smtp_server = 'my.mailhost.com';
  29.  
  30.     # init the server
  31.   my $smtp = Net::SMTP->new(
  32. #                $smtp_server,
  33.                 Timeout => 60, 
  34.                 Debug   => $debug,
  35.                );
  36.  
  37.     # I'm $smtp_from
  38.   $smtp->mail($smtp_from) or warn ("Failed to specify a sender [$smtp_from]\n");
  39.  
  40.     # Please Send the email to $smtp_to
  41.   $smtp->to($smtp_to) or warn ("Failed to specify a recipient [$smtp_to]\n");
  42.  
  43.     # Please send this data
  44.   $smtp->data([$mail_message]) or warn ("Failed to send a message\n");
  45.  
  46.     # I'm over
  47.   $smtp->quit or warn ("Failed to quit\n");
  48.  
  49. } #  end of sub send_mail
  50.  
  51.  
  52.  
  53. # don't remove
  54.  
  55. 1;
  56.  
  57.