The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

Test::Mock::Net::Server::Mail - mock SMTP server for use in tests

VERSION

version 1.00

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;

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.

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.

AUTHOR

Markus Benning <ich@markusbenning.de>

COPYRIGHT AND LICENSE

This software is copyright (c) 2015 by Markus Benning <ich@markusbenning.de>.

This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.