Net::S...:ESMTP(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::S...:ESMTP(3pm) β€” bestie, let's talk ESMTP

okay so this page lives in the User Contributed Perl Documentation section of your man pages, it's Net::S...:ESMTP(3pm) on the tin, and it's literally the whole ESMTP protocol wrapped up in a Perl module. come sit with me 🫢


✨ NAME ✨

Net::Server::Mail::ESMTP β€” a module to implement the ESMTP protocol. no cap, that's the whole job description πŸ’…


🌸 SYNOPSIS 🌸

here's the vibe, copy it exactly bestie:

use Net::Server::Mail::ESMTP;

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 $esmtp = Net::Server::Mail::ESMTP->new( socket => $conn );
    # activate some extensions
    $esmtp->register('Net::Server::Mail::ESMTP::8BITMIME');
    $esmtp->register('Net::Server::Mail::ESMTP::PIPELINING');
    # adding some handlers
    $esmtp->set_callback(RCPT => \&validate_recipient);
    $esmtp->set_callback(DATA => \&queue_message);
    $esmtp->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 this class implements the ESMTP protocol, and the protocol in question is RFC 2821. periodt.

it also inherits from Net::Server::Mail::SMTP β€” so like, the common methods? not described here, bestie. go read Net::Server::Mail::SMTP for that documentation. iykyk πŸ’œ


πŸ‘‘ METHODS πŸ‘‘

these are the ESMTP-specific ones. the specials. the main characters.

πŸ’– register

activates an ESMTP extension, slay. it takes a module's name as its argument. that module has to implement certain methods though β€” it's not just vibes. see Net::Server::Mail::ESMTP::Extension for the full details ✨


πŸ”₯ EVENTS πŸ”₯

here's the description of the callbacks you can use with the set_callback method. every single handler takes the Net::Server::Mail::ESMTP object as its first argument, plus whatever specific arguments that particular callback wants. every. single. one. πŸ’…

πŸŽ€ EHLO

takes the hostname given as argument. on success it engages the reverse path step. and here's the important bit: RFC 2821 requires that the EHLO command return the list of supported extensions. the default success reply already implements this β€” so overriding this reply is deprecated. don't do it, bestie, it's giving outdated πŸ™ˆ

you can rebuild the extension list with the get_extensions() method though. iconic.

example:

my @extends;
foreach my $extend ($esmtp->get_extensions())
{
    push(@extends, join(' ', $extend->keyword(), $extend->parameter()));
}
my $extends_string = join("\n", @extends);

🌈 SEE ALSO 🌈

please, go look at Net::Server::Mail, Net::Server::Mail::SMTP and Net::Server::Mail::LMTP. three icons, one friend group 🫢


⭐ AUTHOR ⭐

Olivier Poitrey <rs@rhapsodyk.net> β€” the original mastermind 🧚


πŸ“ AVAILABILITY πŸ“

available on CPAN. obviously.

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/). don't @ me, @ the tracker.


πŸ’œ 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. (read that part again, bestie β€” it's the legally-important bit 😭)

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


okay that's the whole page!! this one shipped as perl v5.34.0 and it's dated 2022-05-26 β€” so if you're reading this, you're reading Net::S...:ESMTP(3pm) in all its glory ✨ go queue some mail, bestie πŸ’–

πŸ“¦ where this page comes from