[freeside-commits] branch FREESIDE_4_BRANCH updated. 44966ebb81f3dba2aeefa108744edb960320614c
Mitch Jackson
mitch at freeside.biz
Tue May 22 18:33:14 PDT 2018
The branch, FREESIDE_4_BRANCH has been updated
via 44966ebb81f3dba2aeefa108744edb960320614c (commit)
from 0b377f833567c5fd460c11d75bdb5c59a67556c4 (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
- Log -----------------------------------------------------------------
commit 44966ebb81f3dba2aeefa108744edb960320614c
Author: Mitch Jackson <mitch at freeside.biz>
Date: Tue May 22 21:29:10 2018 -0400
RT# 73421 Simulated SMTP server for testing E-Mail
diff --git a/bin/fakesmtpserver.pl b/bin/fakesmtpserver.pl
new file mode 100755
index 000000000..1f2ca3f31
--- /dev/null
+++ b/bin/fakesmtpserver.pl
@@ -0,0 +1,53 @@
+#!/usr/bin/env perl
+
+=head1 Fake SMTP Server
+
+While this script is running, creates an SMTP server at localhost port 25.
+
+Can only accept one client connection at a time. If necessary,
+it could be updated to fork on client connections.
+
+When an e-mail is delivered, the TO and FROM are printed to STDOUT.
+The TO, FROM and MSG are saved to a file in $message_save_dir
+
+=cut
+
+use strict;
+use warnings;
+
+use Carp;
+use Net::SMTP::Server;
+use Net::SMTP::Server::Client;
+use Net::SMTP::Server::Relay;
+
+my $message_save_dir = '/home/freeside/fakesmtpserver';
+
+mkdir $message_save_dir, 0777;
+
+my $server = new Net::SMTP::Server('localhost', 25) ||
+ croak("Unable to handle client connection: $!\n");
+
+while(my $conn = $server->accept()) {
+ my $client = new Net::SMTP::Server::Client($conn) ||
+ croak("Unable to handle client connection: $!\n");
+
+ $client->process || next;
+
+ open my $fh, '>', $message_save_dir.'/'.time().'.txt'
+ or die "error: $!";
+
+ for my $f (qw/TO FROM/) {
+
+ if (ref $client->{$f} eq 'ARRAY') {
+ print "$f: $_\n" for @{$client->{$f}};
+ print $fh "$f: $_\n" for @{$client->{$f}};
+ } else {
+ print "$f: $client->{$f}\n";
+ print $fh "$f: $client->{$f}\n";
+ }
+
+ }
+ print $fh "\n\n$client->{MSG}\n";
+ print "\n";
+ close $fh;
+}
-----------------------------------------------------------------------
Summary of changes:
bin/fakesmtpserver.pl | 53 +++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 53 insertions(+)
create mode 100755 bin/fakesmtpserver.pl
More information about the freeside-commits
mailing list