#!/usr/bin/perl -wT
#
# smtp.pl -- little smtp smarthost-relay 
# 1999/10/07 Rich Lafferty <rich@alcor.concordia.ca>
#
# NO WARRANTY, etc. Released under the same terms as Mutt itself.
# In particular, if you lose mail because of this, it's entirely
# your problem. I don't recommend using this; it's trivial to get
# a basic smtpd that does the right thing installed on your system,
# and that's how the Unix mail subsystem is designed to work. (Yes,
# Pine and Netscape get it wrong. They're both wrong in myriad other
# ways, too, so it's no surprise.) If your reason for looking for
# something like this is because you don't want to set up Sendmail,
# I can't say I blame you -- I personally use exim on boxes that move
# very little mail, and postfix or qmail on larger ones.
# 
# Add the following line to your .muttrc:
#
#   set sendmail="/path/to/smtp.pl"
# 

require 5.004;
use strict;
use Net::SMTP;
use Net::Domain;

# Change this line!
my $smarthost = "your.mail.host";

my $smtp = Net::SMTP->new($smarthost, Debug => 0);
my $me = $ENV{USER} . '@' . Net::Domain::hostfqdn();
$smtp->mail($me) or die "Invalid sender\n";
foreach my $recipient (@ARGV) {
    if ($recipient ne "--") {
	$recipient .= "." . Net::Domain::hostdomain() 
	    unless $recipient =~ /\./;
	$smtp->to($recipient) || warn "Invalid recipient\n";
    }
}
$smtp->data() or die "Can't make a message\n";
while (<STDIN>) { $smtp->datasend($_) or die Can't make a message (c)\n"; }
$smtp->dataend() or die "Message delivery refused\n";
$smtp->quit or warn "SMTP session terminated abnormally\n";

__END__


