Alphamonk IT Systems Home | Articles | Contact Us | Services





Login
Username:

Password:

Remember me



Lost Password?

Register now!

Mailing from Perl

Published by Alphamonk on 2009/3/18 (221 reads)
I use this as a function in many of my scripts and thought it could be useful to some of you.


use strict;
use 
warnings;

my $mailfrom      "sender@yourdomain.com";
my $path $ENV{PATH};
my $user $ENV{USER};


my $mailto  "receiver1@yourdomain.com, receiver2@yourdomain.com";
my $message = <<MESSAGE;
This is mail sent from Sender to notify you of success or 
failure of suchandsuch build script in this path
MESSAGE
my $subject 
"Build Info";

notify($subject$message$mailfrom);

sub notify{
  (
$subject$message$mailfrom) = @_;
  if(
$mailto && $mailfrom && $subject){
    
open(MAIL"|/usr/sbin/sendmail -t");
    
## Mail Header
    
print MAIL "To: $mailton";
    print 
MAIL "From: $mailfromn";
    print 
MAIL "Subject: $subjectnn";
    
## Mail Body
    
print MAIL "$messagen";
  }
  
close(MAIL);
  exit;
}

Navigate through the articles
hex2binary script Next article
Voters total: 0
Average: 0
The comments are owned by the poster. We aren't responsible for their content.
Main Menu
ads
AddTo Social bookmarking block




� 2008 All Rights Reserved