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 |
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. |
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 |
sorry
|
All times are GMT -5. The time now is 05:32 PM. |