Server::Relay(3pm)

πŸ“¦
version 1.1 Β· 2 versions
  • 1.1 Β· debian bookworm, debian trixie, ubuntu noble, ubuntu resolute, ubuntu stonking (latest)
  • 1.1 Β· ubuntu jammy
, in debian bookworm, debian trixie, ubuntu noble, ubuntu resolute, ubuntu stonking

πŸ’– NAME πŸ’–

Net::SMTP::Server::Relay β€” bestie, it's a simple relay module for Net::SMTP::Server. That's it, that's the whole vibe. ✨


πŸ¦‹ SYNOPSIS πŸ¦‹

okay so here's the whole flex, code verbatim because I would never:

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});
}

notice how we spawn the client, let it do its lil transaction, then hand the whole thing off to the relay? iconic behavior honestly. 🫢


🌸 DESCRIPTION 🌸

So. The Net::SMTP::Server::Relay module implements simple SMTP relaying for use with the Net::SMTP::Server module. And when I say "all this module does" β€” I mean it. It takes a given message, iterates through the list of recipients, does DNS lookups for the associated MX record, and delivers the messages. That's the whole job. She's a hard worker and she knows her lane. πŸ’…

The way it pulls this off is by making extensive use of the plethora of other modules already implemented for Perl β€” specifically the DNS and Net::SMTP modules in this case. And honestly? It should give but a glimpse of the potential for extending Net::SMTP::Server's functionality to provide a full-featured SMTP server, native to Perl. no cap. πŸ”₯

The example up there in the SYNOPSIS shows off how you use the Net::SMTP::Server::Relay modules β€” you literally just instantiate the module, passing along the sender, recipients, and message. Periodt. πŸŽ€

More formally, bestie:

$relay = new Net::SMTP::Server::Relay($from, @to, $msg);

Where:

  • $from is the sender
  • @to is an array containing the list of recipients
  • $msg is the message to relay

Like. That's it. Three things. Go off. πŸ‘‘


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.

fr fr read the license before you go distributing things, it's giving responsible main character energy ⭐

πŸ‘‘ SEE ALSO πŸ‘‘

  • Net::SMTP::Server::Server
  • Net::SMTP::Server::Client

go read those next bestie, they're the whole supporting cast πŸŒˆπŸ’–


and that's a wrap!! this lil page came to you courtesy of perl v5.34.0 and the date 2022-06-30 β€” slay, stay hydrated, and may all your MX records resolve πŸ§šπŸ“πŸ’–βœ¨

πŸ“¦ where this page comes from