Net::S...l::SMTP(3pm)

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

πŸ’Œ Net::Server::Mail::SMTP β€” the manual page, but make it cute

okay so bestie, this is the 3pm manual page for Net::Server::Mail::SMTP, straight out of the User Contributed Perl Documentation pile. She's giving very much "I speak SMTP so you don't have to" and honestly? obsessed. let's get into it πŸ’…


✨ NAME ✨

Net::Server::Mail::SMTP β€” a module to implement the SMTP protocol πŸ¦‹


πŸŽ€ SYNOPSIS πŸŽ€

here's the vibe, in code, untouched, exactly as the ancestors wrote it:

use Net::Server::Mail::SMTP;

my @local_domains = qw(example.com example.org);
my $server = IO::Socket::INET->new( Listen => 1, LocalPort => 25 );

my $conn;
while($conn = $server->accept)
{
    my $smtp = Net::Server::Mail::SMTP->new( socket => $conn );
    $smtp->set_callback(RCPT => \&validate_recipient);
    $smtp->set_callback(DATA => \&queue_message);
    $smtp->process();
    $conn->close();
}

sub validate_recipient
{
    my($session, $recipient) = @_;

    my $domain;
    if($recipient =~ /\@(.*)>\s*$/)
    {
        $domain = $1;
    }

    if(not defined $domain)
    {
        return(0, 513, 'Syntax error.');
    }
    elsif(not(grep $domain eq $_, @local_domains))
    {
        return(0, 554, "$recipient: Recipient address rejected: Relay access denied");
    }

    return(1);
}

sub queue_message
{
    my($session, $data) = @_;

    my $sender = $session->get_sender();
    my @recipients = $session->get_recipients();

    return(0, 554, 'Error: no valid recipients')
        unless(@recipients);

    my $msgid = add_queue($sender, \@recipients, $data)
      or return(0);

    return(1, 250, "message queued $msgid");
}

πŸ’– DESCRIPTION πŸ’–

so basically this class implements the SMTP (RFC 821) protocol. periodt. 🫢

but here's the tea: it does not implement the extension mechanism introduced in RFC 2821. nope, not here, not today. if you want that capability you gotta go use Net::Server::Mail::ESMTP instead. iykyk ✨

also, this class inherits from Net::Server::Mail, so if you want the documentation for the common methods, go read Net::Server::Mail. she's the mother module, respect her πŸ‘‘


🌸 METHODS 🌸

SMTP-specific methods only, bestie. the rest live with the parent.

πŸ’… get_sender

returns the sender of the current session. returns undefined if the reverse path step is not complete. no reverse path, no sender, no cap.

πŸ’… get_recipients

returns the list of recipients supplied by client. returns undef if the forward_path step is not engaged. returns an empty list if no recipients succeed. so like, three different outcomes, read carefully πŸ“


πŸ”₯ EVENTS πŸ”₯

these are the callbacks you can use with the set_callback method. all handles take the Net::Server::Mail::SMTP object as the first argument, plus whatever arguments that specific callback wants. every single one. no exceptions πŸ’–

🧚 HELO

takes the hostname given as argument. engages the reverse path step on success.

sub helo_handle
{
    my($session, $hostname) = @_;

    if($hostname eq 'localhost')
    {
        return(0, 553, q(I don't like this hostname, try again.));
    }

    # don't forgot to return a success reply if you are happy with
    # command's value
    return 1;
}

🧚 NOOP

this handler takes no argument. literally none. it's the chill one 😌

🧚 EXPN

command not yet implemented.

handler takes address as argument.

🧚 EXPN

command not implemented, deprecated by RFC 2821.

handler takes no argument.

bestie yes it's listed twice in the source, that's just how the page is built, we don't edit the lore, we only vibe with it πŸ™ˆ

🧚 VRFY

command not yet implemented.

handler takes address as argument.

🧚 HELP

command not yet implemented.

handler takes a command name as argument.

🧚 MAIL

handler takes address as argument. on success, it engages the forward path step and keeps the given address for later use (grab it with the get_sender() method). she remembers things for you, iconic πŸ‘‘

🧚 RCPT

handler takes address as argument. on success, it engages the mail data path step and pushes the given address into the recipient list for later use (grab it with the get_recipients() method). one of these per recipient, slay ✨

🧚 SEND

command not implemented.

handler takes no argument.

🧚 SOML

command not implemented.

handler takes no argument.

🧚 SAML

command not implemented.

handler takes no argument.

🧚 DATA

this handler is called after the final . sent by client. it takes data as argument in a scalar reference. you should queue the message and reply with the queue ID. that's your moment, bestie, go queue πŸŽ€

🧚 DATA-INIT

this handler is called before entering the "waiting for data" step. the default success reply is a 354 code telling the client to send the mail content. very "okay go ahead, we're listening" of it πŸ’œ

🧚 DATA-PART

this handler is called at each part of mail content sent. it takes as argument a scalar reference to the part of data received.

⚠️ it is deprecated to change the contents of this scalar. don't touch it, don't poke it, hands off 🫢

🧚 RSET

handler takes no argument.

on success, all steps are initialized and the sender/recipients list are flushed. full reset, clean slate, main character energy 🌈

🧚 QUIT

handler takes no argument.

connection is closed after this command. this behavior may change in future β€” you will probably be able to control the closing of connection. so like, watch this space, ngl πŸ’€


🌟 SEE ALSO 🌟

please, see Net::Server::Mail, Net::Server::Mail::ESMTP and Net::Server::Mail::LMTP. go read your siblings, bestie, they're all valid πŸ’–


πŸ¦‹ AUTHOR πŸ¦‹

Olivier Poitrey <rs@rhapsodyk.net>


⭐ AVAILABILITY ⭐

available on CPAN.

anonymous Git repository:

git clone git://github.com/rs/net-server-mail.git

Git repository on the web:

<https://github.com/rs/net-server-mail>


😭 BUGS 😭

please use the CPAN system to report a bug (http://rt.cpan.org/). be nice, be specific, include the details, we're all doing our best out here πŸ’œ


πŸ‘‘ LICENCE πŸ‘‘

this library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version.

this library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. see the GNU Lesser General Public License for more details.

you should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA


Copyright (C) 2002 - Olivier Poitrey, 2007 - Xavier Guimard


and that's the whole page bestie, no skips, no cuts, every single flag and callback accounted for πŸ’– this was perl v5.34.0, dated 2022-05-26, and that's your lot from Net::S...l::SMTP(3pm) β€” now go queue some mail, you absolute legend 🫢✨

πŸ“¦ where this page comes from