Net::SMTP::Server::Client(3pm)

Net::SMTP::Server::Client3pm

Client session handling for net::smtp::server.

Usage

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

Overview

The Net::SMTP::Server::Client module implements all the session handling required for a Net::SMTP::Server::Client connection. The above example demonstrates how to use Net::SMTP::Server::Client with Net::SMTP::Server to handle SMTP connections.

$client = new Net::SMTP::Server::Client($conn)

Net::SMTP::Server::Client accepts one argument that must be a handle to a connection that will be used for communication.

Once you have a new client session, simply call:

$client->process

This processes an SMTP transaction. THIS MAY APPEAR TO HANG -- ESPECIALLY IF THERE IS A LARGE AMOUNT OF DATA BEING SENT. Once this method returns, the server will have processed an entire SMTP transaction, and is ready to continue.

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. :)

Releases

11 releases since Debian 3.1 (Sarge); the text changed 4 times.

  1. 3.1–4.0
  2. 5.0
  3. 6.0–8
  4. 9–11
  5. 12–13

From libnet-smtp-server-perl 1.1-7 in Debian 13 (Trixie). Parsed by carta from the page's man source.