improve handling of SMTP test server

This commit is contained in:
Graham Knop 2009-04-30 18:17:23 +00:00
parent 1c7d8c5050
commit 7d0f1e4b8a
2 changed files with 51 additions and 45 deletions

View file

@ -1,20 +1,18 @@
my $HOST = shift;
my $PORT = shift;
my $EMAILS = shift || 1;
die "HOST must be first argument"
unless $HOST;
die "PORT must be second argument"
unless $PORT;
use strict;
use warnings;
use JSON qw( to_json );
use Net::SMTP::Server;
use Net::SMTP::Server::Client;
my $server = Net::SMTP::Server->new( $HOST, $PORT );
my ($HOST, $PORT) = @ARGV;
my $counter = 0;
die "HOST must be first argument"
unless $HOST;
die "PORT must be second argument"
unless $PORT;
my $server = Net::SMTP::Server->new( $HOST, $PORT );
$| = 1;
@ -25,16 +23,10 @@ CONNECTION: while ( my $conn = $server->accept ) {
to => $client->{TO},
from => $client->{FROM},
contents => $client->{MSG},
counter => $counter,
emails => $EMAILS,
});
print "\n";
last CONNECTION if ++$counter >= $EMAILS;
}
sleep 3;
exit(0);
=head1 NAME
t/smtpd.pl - A dumb SMTP server.