[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [cobalt-users] Sending mail with attachment via cron?



This should get you started... This perl program will open a file
($mailfile) and send you the files contents, and then clear out the file
when it is finished.  It's fairly basic, just piping commands into
sendmail.  It should make sense if you're familiar with perl, if not,
just ask for more info/explanation. 

I use a longer version of this script that fires from cron everyday at
4:00pm, you'll obviously have to make the cron entry to call the script
at your desired interval.

Hope it helps.

#!/usr/bin/perl

#Params to pass on to sendmail, change as needed.
$mailrecip = 'user@xxxxxxxxxx';
$mailfrom  = 'Someone';
$mailfile  = "/home/file.txt";

    open (MAIL, "|/usr/lib/sendmail -t -f$mailfrom");
    print MAIL "From: $mailfrom \n";
    print MAIL "To: $mailrecip \n";
    print MAIL "Subject: Here is your text file... \n";
    print MAIL "\n";
    print MAIL "Some text in the message body...\n\n";
    open(FILE,$mailfile);

    while (<FILE>){
         print MAIL $_;
    }

    print MAIL ".\n";
    close MAIL;

open(FILE,">$mailfile");
print FILE "";
close FILE;


On Wed, 2003-05-28 at 14:51, Ren=?ISO-8859-1?B?6SBN+A==?=lsted wrote:
> Hi all
> I need to send a mail containing a file or contents of a text file via
> crontab. How is that done?
> Or is it possible to have PGP send a mail with the encrypted file?
>