DESCRIPTION

Test::Mock::Net::Server::Mail is a mock SMTP server based on Net::Server::Mail. If could be used in unit tests to check SMTP clients.

It will accept all MAIL FROM and RCPT TO commands except they start with 'bad' in the user or domain part. And it will accept all mail except mail containing the string 'bad mail content'.

If a different behaviour is need a subclass could be used to overwrite process_<cmd> methods.

SYNOPSIS

In a test:

use Test::More;
use Test::Mock::Net::Server::Mail;

use_ok(Net::YourClient);

my $s = Test::Mock::Net::Server::Mail->new;
$s->start_ok;

my $c = Net::YourClient->new(
  host => $s->bind_address,
  port => $s->port,
);
# check...

$s->stop_ok;

ATTRIBUTES

bind_address (default: "127.0.0.1")

The address to bind to.

start_port (default: random port > 50000)

First port number to try when searching for a free port.

support_8bitmime (default: 1)

Load 8BITMIME extension?

support_pipelining (default: 1)

Load PIPELINING extension?

support_starttls (default: 1)

Load STARTTLS extension?

METHODS

port

Retrieve the port of the running mock server.

pid

Retrieve the process id of the running mock server.

before_process( $smtp )

Overwrite this method in a subclass if you need to register additional command callbacks via Net::Server::Mail.

Net::Server::Mail object is passed via $smtp.

process_ehlo( $session, $name )

process_mail( $session, $addr )

process_rcpt( $session, $addr )

process_data( $session, \$data )

Overwrite on of this methods in a subclass if you need to implement your own handler.

main_loop

Start main loop.

Will accept connections forever and will never return.

start

Start mock server in background (fork).

After the server is started $obj->port and $obj->pid will be set.

start_ok( $msg )

Start the mock server and return a test result.

stop

Stop mock smtp server.

stop_ok( $msg )

Stop the mock server and return a test result.