nevermind, figured it out ;) (re: simple commandline one-shot emailer)

Peter Marreck prm1 at cornell.edu
Mon Feb 2 22:30:51 PST 2004


I just went ahead and coded a perl script to accomplish the job. 
Discovered "Net::SMTP" was included in the stock Perl distribution and 
then googled it for script ideas since I'm a perl n00b. Enjoy... feel 
free to add error-handling, I was just going for the quick-and-dirty 
here. I saved it as "email" and chmod +x'ed it. Usage is like so:
./email -server=mail.optonline.com -from=billc at optonline.com 
-to=monica at optonline.com -subject="altoids" -body="Curiously strong 
mints. Indeed."

#!/usr/bin/perl -s
use Net::SMTP;
# parameters that this script accepts: -server, -from, -to, -subject, 
-body
# This debug flag will print debugging code,
# depending on its value.
# Set this to 1 to print debug code.
# Set it to 0 to turn it off.
my $DEBUG = 0;
# Create a new SMTP object
$smtp = Net::SMTP->new($server, Debug => $DEBUG);
# If you can't connect, don't proceed with the rest of the script
die "Couldn't connect to server" unless $smtp;
# Initiate the mail transaction
$smtp->mail( $from );
$smtp->to( $to );
# Start the mail
$smtp->data();
# Send the header
$smtp->datasend("To:  $to\n");
$smtp->datasend("From:  $from\n");
$smtp->datasend("Subject: $subject\n");
$smtp->datasend("\n");
# Send the body.
$smtp->datasend("$body\n\n");
# Send the termination string
$smtp->dataend();
# Close the connection
$smtp->quit();



More information about the X-Unix mailing list