Приглашаем посетить
Сладков (sladkov.lit-info.ru)

Easy Mail

#!/usr/bin/perl
######## EasyMail #########
# Version: 1.0.1 created: 8/5/96
# For use on most Unix operating systems
# execute this program by typing this at the command line:
# perl easymail.pl
######################################################################## 
# This is a simple program to make sending e-mail from the command     #
# line a bit easier. Sending e-mail from the command line (those die-  #
# hards that still do) have to go through a series of "invisible"      #
# codes to send e-mail (i.e. the mysterious "control d" on a blank     #
# line to send the mail, and the unclear method of adding a subject    #
# line). EasyMail justs asks the user a series of questions and then   #
# sends the message. EasyMail also creates log files for each time the #
# the user sends mail. EasyMail is free to use by anyone. Consult the  #
# the README file for some simple instructions in editing this program #
# to work properly on your Unix system. EasyMail was written by:       #
# David Palmer <dave@upstatepress.com> http://upstatepress.com/cgi/    #
########################################################################

#these variables need to be defined first:
$mailprog = '/usr/sbin/sendmail';
$homedir = '/usr/home/upstate';
$date = "/bin/date";
$ext = 'elog';

#simple greeting
print "Hello, welcome to EasyMail!\n";

#lets do this
&continue;

sub continue {

	print "What is your name?\n";
	$name = <STDIN>;
	chop ($name);

	print "What is your e-mail address?\n";
	$my_email = <STDIN>;
	chop ($my_email);

	print "What is the recipient's real name?\n";
	$realname = <STDIN>;
	chop ($realname);

	print "What is the address of the recipient?\n";
	$recipient = <STDIN>;
	chop ($recipient);

	print "What would you like the subject to be?\n";
	$subject = <STDIN>;
	chop ($subject);

	print "Okay, just type in the message. Please make it brief!\n";
	$message = <STDIN>;
	chop ($message);
		}

#get date info
&get_date;

#Now we send the e-mail message
&sendmail;

#Last but not least, lets make a simple log
&make_log;

sub get_date {
	
	@days = ('Sunday','Monday','Tuesday','Wednesday','Thursday',
			'Friday','Saturday');
	@months = ('January','February','March','April','May','June',
			'July','August','September','October','November',
			'December');

($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time);
if ($hour < 10) { $hour = "0$hour"; }
if ($min < 10) { $min = "0$min"; }
if ($sec < 10) { $sec = "0$sec"; }

$date = "$days[$wday], $months[$mon] $mday, 19$year at $hour\:$min\:$sec";
		}

sub sendmail {
open(MAIL, "| $mailprog -t") || die "I shall not DO that!\n";
	print MAIL "To: $realname <$recipient>\n";
	print MAIL "From: $name <$my_email>\n";
	print MAIL "Subject: $subject\n";
	print MAIL "-----------------------------------------------\n";
	print MAIL "$message\n";
	print MAIL "-----------------------------------------------\n";
close(MAIL);
		}

sub make_log {
open(NEWFILE, ">$homedir/$realname\.$ext") || die "Can't do it man\n";
	print NEWFILE "You sent an e-mail using EasyMail on: $date\n";
	print NEWFILE "Below are the contents of that message\n";
	print NEWFILE "\n";
	print NEWFILE "-----------------------------------------------\n";
	print NEWFILE "To: $realname <$recipient>\n";
	print NEWFILE "Subject: $subject\n";
	print NEWFILE "Message: $message\n";
	print NEWFILE "-----------------------------------------------\n";
	print NEWFILE "\n";
			}
print "Your mail has been sent. Thank you!\n"