#!/usr/bin/perl --
#
# Usage: sendemail [-s 'subject'] 'dest'
#
# Send an email to the outside world via mail.inx.com.br, as
# edrx@inx.com.br; the body is read from stdin and there is still no
# provision for extra header lines. Also, I think that this only works
# if I'm connecting to inx by modem, logged as edrx.
#
# Date: 2000may08.
#
# (find-es "mail" "Net::SMTP2")
# (find-es "perl" "Getopt::Std")
# (find-es "perl" "argc")
# (eeman "perlvar" "delimiters")

# file /usr/bin/* | grep -i perl | perl -nle '/^(.*?):/ && print $1' | tee ~/o
# l $(<~/o)

@ARGV || die "usage: $0 [-s subject] recipient\n";

use Getopt::Std;
getopt("s");
$subj = $opt_s;

$to = $ARGV[0];

undef $/;
$txt = <STDIN>;

$mailhost = "mail.inx.com.br";

# $txt = `date "+Test: %Y%b%d %T"`;
# $mailhost = "localhost";
# print "(subj:).$subj. (to:).$to.  (txt:).$txt.\n"; exit;


use Net::SMTP;
$smtp = Net::SMTP->new($mailhost,
		        Hello => 'inx.com.br',
		        Debug => 1);
$smtp->mail('edrx@inx.com.br');
$smtp->to($to);
$smtp->data();
$smtp->datasend("To: $to\n");
$subj
  && $smtp->datasend("Subject: $subj\n");
$smtp->datasend("\n");
$smtp->datasend($txt);
$smtp->dataend();
$smtp->quit;
