← Documentation Index

NAME

Test::Mailmunge::SMTPServer - run a fake SMTP server for unit-test purposes

ABSTRACT

Test::Mailmunge::SMTPServer runs a fake SMTP server. It is used (for example) to test Mailmunge::Test::SMTPForward

SYNOPSIS

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

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, then 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.

AUTHOR

Dianne Skoll <dianne@skollsoft.com>

LICENSE

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

Copyright © 2024 Skoll Software Consulting