Test::M...TPServer(3)

πŸ“¦ version 3.20, in alpine 3.24

Welcome to the User Contributed Perl Documentation page for Test::Mailmunge::SMTPServer β€” yes, the header is stylized as Test::M...TPServer(3), and no, we are not gatekeeping the full name πŸ’…βœ¨

πŸ’– NAME πŸ’–

Bestie, meet Test::Mailmunge::SMTPServer: it runs a fake SMTP server for unit-test purposes. That's the whole assignment, and it ate πŸŽ€

🌸 ABSTRACT 🌸

Test::Mailmunge::SMTPServer runs a fake SMTP server. It is used (for example) to test Mailmunge::Test::SMTPForward. No cap, that's the abstract πŸ¦‹

✨ SYNOPSIS ✨

Okay so the starter pack is literally:

use Test::Mailmunge::SMTPServer;
my $server = Test::Mailmunge::SMTPServer->new();
my $port = $server->{port};
# Now interact with server on 127.0.0.1 at port $port

# DON'T FORGET to stop the server when done!
$server->stop_server();

Then you interact with server on 127.0.0.1 at port $port, and please β€” DON'T FORGET to stop the server when done. The comment is yelling for a reason 🫢

πŸ› οΈ CONSTRUCTOR πŸ› οΈ

Test::Mailmunge::SMTPServer->new($callback1 => \&func1, ...)

Constructs and starts a new test SMTP server. Supply callbacks to tell the server how to respond to SMTP client commands. The possible callbacks are:

  • connect => \&coderef β€” if supplied, coderef is called with $self as the only argument when an SMTP client connects.

It should print a reply to the socket $self->{sock}. If no connect callback is supplied, then the default response printed to the socket is:

"220 localhost.example.com ESMTP\r\n"
  • ehlo => \&coderef β€” if supplied, then when an SMTP client issues the EHLO command, coderef is called with $self and $line as arguments, where $line is the complete line read from the SMTP client.

It should print a reply to the socket $self->{sock}. If no ehlo callback is supplied, then the default response printed to the socket is:

"250-localhost.example.com\r\n250-SIZE 100000\r\n250 8BITMIME\r\n"
  • helo => \&coderef β€” similar to ehlo, but called if the client issues the HELO command. The default response is:
"250 localhost.example.com\r\n"
  • mail => \&coderef β€” similar to ehlo, but called if the client issues the MAIL From: command. The default response is:
"250 2.1.0 Ok\r\n"
  • rcpt => \&coderef β€” similar to ehlo, but called if the client issues the RCPT To: command. The default response is:
"250 2.1.0 Ok\r\n"
  • data => \&coderef β€” similar to ehlo, but called if the client issues the DATA command. The default response is:
"354 End data with <CR><LF>.<CR><LF>\r\n"

πŸ›‘ INSTANCE METHOD πŸ›‘

$server->stop_server()

Stops the SMTP server. That's it. Clean, simple, iconic πŸ’…

πŸ‘‘ AUTHOR πŸ‘‘

Dianne Skoll <dianne@skollsoft.com>

πŸ“œ LICENSE πŸ“œ

This code is licensed under the terms of the GNU General Public License, version 2.


Mwah πŸ’‹ β€” this Test::M...TPServer(3) page comes from perl v5.42.2, dated 2025-10-05. Byeee πŸ¦‹

πŸ“¦ where this page comes from