Help answer threads with 0 replies.
Go Back > Forums > Non-*NIX Forums > Programming
User Name
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.


  Search this Thread
Old 01-23-2002, 04:18 AM   #1
LQ Newbie
Registered: Dec 2001
Posts: 3

Rep: Reputation: 0
Cron Email Notification - Perl Script


With the help of one of the other posters to this site, I have come up with the following perl script which I run under cron. It checks a directory on my webserver, and if a report has been uploaded to the directory it moves it to a public area of the webserver and issues an email notification...


### Load copy module
use File::Copy;

### Define e-mail sender and e-mail recipient
my $email_sender = "sender/";
my $email_recipient1 = "testaddress1/";
my $email_recipient2 = "testaddress1/";

### Define home directory where file will be uploaded
my $home_dir = "/home/isabelle/Webupdate/reports/inventory";

### Open home directory for reading
opendir (HOME_DIR, $home_dir) or die "Problem opening directory $home_dir: $!";

### Load files that end in ".html" and ".txt" only into @home_dir_array array
my @home_dir_array = grep( /.html$/ || /.doc$/ || /.xls$/ || /.txt$/ , readdir(HOME_DIR));

### Load files that end in ".txt" only into @home_dir_array array
#my @home_dir_array = grep( /.txt$/ , readdir(HOME_DIR));

### Load files that end in ".html", ".txt" and ".doc" into @home_dir_array array
#my @home_dir_array = grep( /.html$/ || /.txt$/ || /.xls$/ || /.doc$/ , readdir(HOME_DIR));

### Close directory handle
closedir (HOME_DIR);

### Begin loop that will send one e-mail for every file matching "html" and "txt"
foreach my $file(@home_dir_array) {
chomp $file; #Remove trailing newline character

print "Found File: $file\n";
`mutt -x -s "File Uploaded to the Website: $file" $email_recipient1 < /dev/null`;
`mutt -x -s "File Uploaded to the Website: $file" $email_recipient2 < /dev/null`;

### Copy file to new webserver directory or print error message if problem
move("$home_dir/$file", "/home/httpd/reports/dir567/reports/Inventory/$file") or print "Problem copying $file to /home/httpd/$file $? $!\n";

This all works fine, however my problem is as follows. When the notification email is sent out, the sender address appears to be and I'm told that most mail servers will not accept mail from "unofficial" internet hosts like this whose IP address and hostname are not ratified. Is this correct? This basically means that I can't send my email notification to anyone outwith my own intranet, which obviously isn't much good.

So my question is this - how can I modify my script to make the sender's email address appear to be something different???

Any advice will be gratefully received!

Old 01-23-2002, 08:45 AM   #2
Registered: Dec 2001
Distribution: redhat
Posts: 154

Rep: Reputation: 30
you're right, not all mail servers will like this, but most will (SMTP is pretty open). i use a similar process and send to my yahoo mail and my corporate email, both work fine. as long as the domains is in the domain name formate (, i think it will work most of the time.

if you want to get really into it, use a free service like dynodns to get a 'real' domain name.
Old 01-23-2002, 11:30 PM   #3
Registered: Nov 2001
Location: US
Distribution: Slackware 14.2
Posts: 375

Rep: Reputation: 115Reputation: 115
Hi James,

You can create a file named ".muttrc" in the users home directory and add the following line to the file:

set from=""

If you want to change the "From:" header for every user (when mutt is the mailer), you can edit /etc/Muttrc and look for a line with "set from". Remove the hash (#) and add the e-mail address within the quotes (should look exactly the same as the line in .muttrc). I've used this setting to send mail to the Internet, so it should work.

The file "/etc/Muttrc" does have a capital M, while the "~/.muttrc" file is a lowercase m.

Old 07-21-2009, 08:56 AM   #4
Senior Member
Registered: Sep 2003
Distribution: Debian Squeeze / Wheezy
Posts: 1,623

Rep: Reputation: 51


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Trouble with perl script in Cron job thack111 Linux - General 7 11-25-2004 03:44 AM
cron e-mail notification adm1329 Linux - Newbie 1 06-20-2004 08:27 PM
Suppress mail notification of cron event? jecoltrin Linux - General 2 02-02-2004 01:37 PM
E-Mail notification to users via SMS (gateway script ok, but notification script?!?) Riku2015 Linux - Networking 10 03-08-2002 11:16 AM
Cron Email Notification(?) jamesyreid Linux - General 2 12-17-2001 11:30 AM > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 06:05 PM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration