Server(3pm)
π NAME π
Net::SMTP::Server β a native Perl SMTP server implementation for Perl. yes bestie, the whole mail server is just Perl. no cap. πͺβ¨
πΈ SYNOPSIS πΈ
use Carp;
use Net::SMTP::Server;
use Net::SMTP::Server::Client;
use Net::SMTP::Server::Relay;
$server = new Net::SMTP::Server('localhost', 25) ||
croak("Unable to handle client connection: $!\n");
while($conn = $server->accept()) {
# We can perform all sorts of checks here for spammers, ACLs,
# and other useful stuff to check on a connection.
# Handle the client's connection and spawn off a new parser.
# This can/should be a fork() or a new thread,
# but for simplicity...
my $client = new Net::SMTP::Server::Client($conn) ||
croak("Unable to handle client connection: $!\n");
# Process the client. This command will block until
# the connecting client completes the SMTP transaction.
$client->process || next;
# In this simple server, we're just relaying everything
# to a server. If a real server were implemented, you
# could save email to a file, or perform various other
# actions on it here.
my $relay = new Net::SMTP::Server::Relay($client->{FROM},
$client->{TO},
$client->{MSG});
}
okay so this is the whole vibe right here β spin up a server, accept a connection, hand it to a client parser, let it cook, then relay the message. the comments in there are the original author's, and honestly? they ate. π
π¦ DESCRIPTION π¦
The Net::SMTP::Server module implements an RFC 821 compliant SMTP server, completely in Perl. that's right, completely. it's extremely extensible, so if you wanna drop in spam filtering, or fancier routing and handling, that's literally so easy to do. π«Ά
there's also a bonus module β Net::SMTP::Server::Relay β that got implemented as an example of just one possible application of all that extensibility. peek the pod for that module for the deets. this extension has been tested on both Unix and Win32 platforms. π
β¨ making a server (it's giving trivial) β¨
$server = new Net::SMTP::Server($host, $port);
this creates a new SMTP::Server. both $host and $port are optional and default to the current hostname and the standard SMTP port (25).
β οΈ but bestie, if you're on a multi-homed machine, you might wanna explicitly say which interface to bind to. fr fr.
π the server loop π
it should look something like this:
while($conn = $server->accept()) {
my $client = new Net::SMTP::Server::Client($conn) ||
croak("Unable to handle client connection: $!\n");
$client->process;
}
the server will keep accepting connections forever. once we've got a connection, we make a new Net::SMTP::Server::Client β that's a fresh client connection that's now being handled. π
the reason processing doesn't kick off right there is so you get room for extensibility or hooks β anything a user might wanna add in after we've accepted the client connection but before we send the initial welcome message to the client. once you're ready to run an SMTP session, you call $client->process.
π heads up: this may HANG while the SMTP transaction is happening, because the client and server are going back and forth talking to each other. and if there's a lot of data to transmit, well... yeah. π
π the fields that get filled in π
once $client->process returns, various fields have been filled in. those are:
$client->{TO}β this is an array containing the intended recipients for this message. there may be multiple recipients for any given message. β¨$client->{FROM}β this is the sender of the given message.$client->{MSG}β the actual message data. :)
the SMTP::Server module performs no other processing for the user. it's meant to give you the building blocks of an extensible SMTP server implementation. π§±
like, for example β using the MIME modules, you can easily process $client->{MSG} to handle MIME attachments, etc. or you could implement ACLs to control who can connect to the server, or what actions get taken.
finally, a suggested use that the author himself uses: as an SMTP relay. there are lots of times he needs access to an SMTP server just to send a message, but doesn't have access to one for whatever reason (firewalls, permissions, etc). you can run your own SMTP server whether under Unix or Win32 environments, and simply point your favorite mail client at it when sending messages. see the Net::SMTP::Server::Relay modules for details on that use. π
π AUTHOR AND COPYRIGHT π
Net::SMTP::Server / SMTP::Server is Copyright(C) 1999, MacGyver (aka Habeeb J. Dihu) <macgyver@tos.net>. ALL RIGHTS RESERVED. β
you may distribute this package under the terms of either the GNU General Public License or the Artistic License, as specified in the Perl README file. π
π₯ SEE ALSO π₯
Net::SMTP::Server::ClientNet::SMTP::Server::Relay
and that's the whole page, bestie!! π this was Server(3pm) from perl v5.34.0, dated 2022-06-30, in the User Contributed Perl Documentation. mwah. π go build something iconic with it π¦β¨
π¦ where this page comes from
- debian bookworm: libnet-smtp-server-perl 1.1-7 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- debian trixie: libnet-smtp-server-perl 1.1-7 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu noble: libnet-smtp-server-perl 1.1-7 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu resolute: libnet-smtp-server-perl 1.1-7 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu stonking: libnet-smtp-server-perl 1.1-7 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms