#! /usr/bin/perl # mail-people.pl # Given an LDAP filter, # Read an email template which contains strings of the form # #ldap_attribute_in_upper_case# and look up those attributes from # the entries selected by the filter, substitute the attribute values # found and send the email to the people. # Provides options to just print to standard output instead of sending # the emails, and also a limit of the number to send (just to check it # seems okay). # Accepts a list of UIDs to send the email to, from stdin or files on # command line. Good for send warning letters to students. # Email sending is based on simple_mime.pl from figure 7.6 on page 185 # of "Network Programming with Perl" by Lincoln Stein # Copyright (C) 2004 Nick Urbanik # This program is free software; you can redistribute it and/or # modify it under the terms of the GNU General Public License # as published by the Free Software Foundation; either version 2 # of the License, or (at your option) any later version. # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. # $Id: mail-people.pl,v 1.6 2004/05/17 04:18:58 nicku Exp $ # $Log: mail-people.pl,v $ # Revision 1.6 2004/05/17 04:18:58 nicku # Made the situation more clear about whether a message was sent or # not. Now we say if it has been "sent" or just "processed". # # Revision 1.5 2004/03/18 18:57:36 nicku # Added CC option (used to CC to Tony Siu) # modified filter to a simple search for uid. Probably should specify # what attribute to search for in an option. # # Revision 1.4 2004/03/08 07:19:43 nicku # Added support for ~/.signature file. # # Revision 1.3 2004/03/06 00:53:14 nicku # Fixed syntax error (Oh dear!) # Added options of sender and bcc to make this useful to others besides myself. # # Revision 1.2 2004/03/06 00:18:35 nicku # Added support for substitution of the subject line as well as the # email body, since it is convenient and trivial to implement. use warnings; use strict; use MIME::Entity; use Carp; use Getopt::Long; use Net::LDAP; use MIME::Types; use constant ICT_LDAP_SERVER => 'ldap.tyict.vtc.edu.hk'; use constant ICT_DIR_BASE => 'ou=People,dc=tyict,dc=vtc,dc=edu,dc=hk'; use constant MAX_EMAIL_COUNT_DEFAULT => 200; use constant DEFAULT_FILTER => '(&(course=41300)(year=2))'; use constant DEFAULT_SCOPE => 'one'; use constant DEFAULT_SENDER => '"Nick Urbanik" '; # Format of the email template: # File is the text of an email, but tokens are replaced # if they occur, such as: # #CN# => cn # #CLASSCODE# => classcode # #GIVENNAME# => givenname # #SN# => sn # #INSTITUTEEMAIL# => instituteEmail # Can use any LDAP attribute in upper case between a pair of hashes. # THE FIRST LINE IS THE SUBJECT. sub read_template($) { my $email_template_file = shift; open TEMPLATE, "<", $email_template_file or die "Unable to open $email_template_file: $!"; my $subject =