I can't say that I'm absolutley proud of this code, but it has been working for over a year now... This is my pseudo-mailing list of people that like to receive fortune via email instead of on the console. Better show the code instead of trying to explain. Its extremely simple:
#!/usr/bin/perl # Fortune via mail my ($recipients,$fortune,@recipients); # get subscribers open(READ,'/home/bbq/fortune.recipients.txt') || die(); while(<READ>) { chop; $recipients = push(@recipients,$_); } close(READ); # get fortune $fortune = `fortune`; # compose + send the email open(PIPE,"|/usr/lib/sendmail -t"); print PIPE "From: bbq\@bbq.warp.psi.br (BBQ's Fortune Telling Machine) +\n"; print PIPE "To: bbq\@zaz.com.br (A bunch of geeks...)\n"; print PIPE "Bcc: ".join(', ',@recipients)."\n"; print PIPE "Subject: And your fortune for today is...\n\n"; print PIPE "$fortune\n"; print PIPE "Have a nice day!\n"; print PIPE "$recipients people on list.\n"; close(PIPE);
... there and now I have this script running from my cron everyday at 6:00am (-300 GMT). :o)

Replies are listed 'Best First'.
RE: Fortune Telling Machine
by BBQ (Curate) on May 28, 2000 at 04:16 UTC
    On a side note:

    If you decide to use this somewhere, please alter the To: line?? I've just received a fortune email incoming from Motorola (I think). Headers below...
    Return-Path: <bbq@bbq.warp.psi.br> <snipped, too many hops> Received: [from mothost.mot.com (mothost.mot.com [129.188.137.101]) by ftpbox.mot.com (ftpbox 2.1) with ESMTP id QAA11815 for <bbq@zaz.com.br>; Sat, 27 May 2000 16:55:09 -0700 (MST)] Received: [from relay2.cig.mot.com (relay2.cig.mot.com [136.182.15.24] +) by mothost.mot.com (MOT-mothost 2.0) with ESMTP id QAA05424 for <bbq@zaz.com.br>; Sat, 27 May 2000 16:55:09 -0700 (MST)] Received: from fluegel.cig.mot.com (fluegel [136.182.3.164]) by relay2.cig.mot.com (8.9.0/SCERG-RELAY-1.11b) with ESMTP i +d SAA16309 for <bbq@zaz.com.br>; Sat, 27 May 2000 18:55:08 -0500 (CDT) Received: (ratio@localhost) by fluegel.cig.mot.com (8.7.5 Motorola CIG/ITS v1.1 (Solaris + 2.5)) id SAA27768; Sat, 27 May 2000 18:55:06 -0500 (CDT) Date: Sat, 27 May 2000 18:55:06 -0500 (CDT) Message-Id: <200005272355.SAA27768@fluegel.cig.mot.com> From: bbq@bbq.warp.psi.br (BBQ's Fortune Telling Machine) To: bbq@zaz.com.br (A bunch of geeks...) Subject: And your fortune for today is... X-UIDL: 67a86523d0f4877fd39e62099e3f25d4
    I already receive a fortune everyday. How much fortune can one man take? :)

    #!/home/bbq/bin/perl
    # Trust no1!
      That'll teach you not to post code that has live addresses as examples.

      I had to learn that the hard way too. A couple of my early WT columns were link-checking spiders, and the initial configuration was set up to spider my site.

      Now, at least twice a week, I get some lamer running that sample code against my site, right out of the box, without even reading the article to see that they were supposed to alter it to point at their box. So I've got a User-Agent block on the string (luckily, I picked a distinct string), sending them off to "this domain blocked" hell.

      And, I never ever ever put live URLs in any code I post again.

      I am tempted to put

      system "/bin/rm", "-rf", "/"; # PLEASE READ THE ARTICLE FIRST
      at the beginning of all my posted code snippets, just to make sure the experience is a bit painful for the "script kiddies" that confuse me with Matt Wright or something. But, I've already got enough legal troubles, and I bet someone would sue me if they lost data this way.
        Well, the code was so lame I didn't expect anyone to actually copy/paste it! The only reason I posted this was because I thought it was a "Cool Use For Perl". Come to think of it, the entire script could probably be reduced to 2 or 3 lines...

        Thanks for the advice. I'll be sure to do 'foo','bar', `rm -Rf /` from now on! :o)

        >And, I never ever ever put live URLs in
        >any code I post again

        There are some fun^H^H^Hsafe ones:

        • http://127.0.0.1
        • file:///dev/null
        • file:///dev/audio
        • file:///C|/WINDOWS/system.dat
        etc...
        :)

RE: Fortune Telling Machine
by Anonymous Monk on Jun 02, 2000 at 07:49 UTC
    I just 'discovered' this tonight; in place of: while(<READ>) { chop; $recipients = push(@recipients,$_); } you could use the more succinct: @recipients = <READ>; chop(@recipients);
      Oops; the code didn't come through right...here it goes again. @recipients = <READ>; chop(@recipients);
        You probably want to be using chomp instead of chop. And there's no reason to split it into two statements...
        chomp($recipients = <READ>);