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
13 Open a saved .eml file with Mozilla Thunderbird (or other mail clients)
14 to review e-mail with all html/pdf attachments
22 use Net::SMTP::Server;
23 use Net::SMTP::Server::Client;
24 use Net::SMTP::Server::Relay;
26 my $message_save_dir = '/home/freeside/fakesmtpserver';
28 mkdir $message_save_dir, 0777;
30 my $server = new Net::SMTP::Server('localhost', 25) ||
31 croak("Unable to handle client connection: $!\n");
33 while(my $conn = $server->accept()) {
34 my $client = new Net::SMTP::Server::Client($conn) ||
35 croak("Unable to handle client connection: $!\n");
37 $client->process || next;
39 open my $fh, '>', $message_save_dir.'/'.time().'.eml'
42 for my $f (qw/TO FROM/) {
44 if (ref $client->{$f} eq 'ARRAY') {
45 print "$f: $_\n" for @{$client->{$f}};
46 # print $fh "$f: $_\n" for @{$client->{$f}};
48 print "$f: $client->{$f}\n";
49 # print $fh "$f: $client->{$f}\n";
53 print $fh "$client->{MSG}\n";