Send an e-mail on a user’s birthday

A quick perl script to send an e-mail to all users on their birthdays.  I’m going to adapt it to also send e-mail to all users on major holidays.

#!/usr/bin/perl
use warnings;
use strict;
use POSIX qw/strftime/;

# Send an e-mail to each user on their birthday
my $date      = strftime('%d-%b',localtime);
my @usernames = `grep $date /usr/local/etc/birthdays`;
my $sendmail  = "/usr/sbin/sendmail -t";
my $reply_to  = "Reply-to: postmaster\@lakemasoniccenter.org\n";
my $subject   = "Subject: Happy Birthday from Lake Lodge #189\n";

foreach (@usernames) { 
        my $gcos    = (getpwnam((split(/:/, $_))[0]))[6];
        my $fname   = (split(/ /, (split(/,/, $gcos))[0]))[0];
        my $to      = "To: " . (split(/:/, $_))[0];
        my $fortune = `fortune`;
        my $content = "Happy Birthday, brother $fname, from Lake Lodge #189 F&AM, WI!  Here's your birthday fortune:\n\n$fortune";

        open(SENDMAIL, "|$sendmail") or die "Cannot open $sendmail: $!";
        print SENDMAIL $reply_to;
        print SENDMAIL $subject;
        print SENDMAIL $to;
        print SENDMAIL "Content-type: text/plain\n\n";
        print SENDMAIL $content;
        close(SENDMAIL);
        #print "$reply_to\0$subject\0$to\nContent-type: text/plain\n\n$content\n.\n";
}
Advertisements
  1. Leave a comment

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: