#!/usr/bin/perl use Net::SMTP::Server; use Net::SMTP::Server::Client; use Getopt::Long; use strict; my $port = 25; # Default listen port my $bindaddr = "localhost"; # Bind to localhost only by default GetOptions ("p=i" => \$port, "b=s" => \$bindaddr) || die "Usage: $0 [-p port] [-b bind-address]"; print "setting up server listening on port $bindaddr:$port\n"; my $server = new Net::SMTP::Server($bindaddr, $port) || die "Cannot setup server: $!"; while(my $conn = $server->accept()) { # Got one incoming connection. # Fork off a child process handling it next if( fork() > 0 ); my $client = new Net::SMTP::Server::Client($conn) || die "Unable to handle client connection: $!"; # Talk to the client $client->process || die "Client didn't send us mail"; # log info and terminate system("logger", "-s", "-p", "local1.notice", "-t", "mailsink", "got mail from ".($client->{"FROM"}). " for ".join(",",@{$client->{"TO"}}). ", message size: ".length($client->{"MSG"})." bytes" ); exit(0); }