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

Barry Lyden blyden at mac.com
Tue Feb 3 03:54:03 PST 2004


Just curious - If you don't mind my asking,  what is this script intended
for? Command line interfaces to the UNIX mail facility are already there -
but controlling the server and from fields are not usually something that
folks do, so you must have a unique reason.


On 2/3/04 12:30 AM, "Peter Marreck" <prm1 at cornell.edu> wrote:

> 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();
> 
> 
> ----------
> Check out the Mac OS X email list FAQ
> http://www.themacintoshguy.com/lists/X.html
> 
> To unsubscribe, E-mail to: <X-Unix-off at lists.themacintoshguy.com>
> To switch to the DIGEST mode, E-mail to
> <X-Unix-digest at lists.themacintoshguy.com>
> Need help from a real person? Try.  <X-Unix-request at lists.themacintoshguy.com>
> 
> ----------
> $14.99 Unlimited Nationwide Mac Dialup and Mac Web Hosting from your Mac ISP
> Serious Mac Internet Solutions From NineWire!   http://macinternetaccess.com
> 
> DVIator   | Run Dual ADC displays on your G4 or just one on an older Mac!
> Dr. Bott  | <http://www.drbott.com/prod/DVIator.html>
> 
>  Support   | Support this list by clicking here before you buy!
> this List  |  http://www.themacintoshguy.com/support.html
> 
> OS X News, Dr.Mac, Forums, Tutorials, Tips, Hints, FAQ?s -
> http://www.osxfaq.com



More information about the X-Unix mailing list