3 =head1 Fake SMTP Server
5 While this script is running, creates an SMTP server at localhost port 25.
7 Can only accept one client connection at a time. If necessary,
8 it could be updated to fork on client connections.
10 When an e-mail is delivered, the TO and FROM are printed to STDOUT.
11 The TO, FROM and MSG are saved to a file in $message_save_dir
19 use Net::SMTP::Server;
20 use Net::SMTP::Server::Client;
21 use Net::SMTP::Server::Relay;
23 my $message_save_dir = '/home/freeside/fakesmtpserver';
25 mkdir $message_save_dir, 0777;
27 my $server = new Net::SMTP::Server('localhost', 25) ||
28 croak("Unable to handle client connection: $!\n");
30 while(my $conn = $server->accept()) {
31 my $client = new Net::SMTP::Server::Client($conn) ||
32 croak("Unable to handle client connection: $!\n");
34 $client->process || next;
36 open my $fh, '>', $message_save_dir.'/'.time().'.txt'
39 for my $f (qw/TO FROM/) {
41 if (ref $client->{$f} eq 'ARRAY') {
42 print "$f: $_\n" for @{$client->{$f}};
43 print $fh "$f: $_\n" for @{$client->{$f}};
45 print "$f: $client->{$f}\n";
46 print $fh "$f: $client->{$f}\n";
50 print $fh "\n\n$client->{MSG}\n";