LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
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.

Notices



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

Rep: Reputation: 0
Cron Email Notification - Perl Script


Hi,

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...

#!/usr/bin/perl

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

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

### 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/reports.dpt-ltd.co.uk/hp567/reports/Inventory/$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 root@www.dpt-private.net 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!

James
 
Old 01-23-2002, 08:45 AM   #2
theFuzzyOne
Member
 
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 (something.com), 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
speck
Member
 
Registered: Nov 2001
Location: California
Distribution: Slackware 14.1
Posts: 283

Rep: Reputation: 56
Hi James,

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

set from="sender@test.com"

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.


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

Rep: Reputation: 48
sorry
 
  


Reply


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


All times are GMT -5. The time now is 02:28 AM.

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