Test::SMTP - Module for writing SMTP Server tests
version 0.05
use Test::SMTP; plan tests => 10; # Constructors my $client1 = Test::SMTP->connect_ok('connect to mailhost', Host => '127.0.0.1', AutoHello => 1); $client1->mail_from_ok('test@example.com', 'Accept an example mail from'); $client1->rcpt_to_ko('test2@example.com', 'Reject an example domain in rcpt to'); $client1->quit_ok('Quit OK'); my $client2 = Test::SMTP->connect_ok('connect to mailhost', Host => '127.0.0.1', AutoHello => 1); ...
This module is designed for easily building tests for SMTP servers.
Test::SMTP is a subclass of Net::SMTP_auth, that is a subclass of Net::SMTP, that in turn is a subclass of Net::Cmd and IO::Socket::INET. Don't be too confident of it beeing a Net::SMTP_auth subclass for too much time, though (v 0.03 changed from Net::SMTP to Net::SMTP_auth so you can control authentication tests better). Compatibility will always try to be kept so you can still call the subclass methods.
Plan tests a la Test::More. Exported on demand (not necessary to export if you are already using a test module that exports plan).
use Test::SMTP qw(plan); plan tests => 5;
Passes if the client connects to the SMTP Server. Everything after name is passed to the Net::SMTP_auth new method. returns a Test::SMTP object.
Net::SMTP_auth parameters of interest: Port => $port (connect to non-standard SMTP port) Hello => 'my (he|eh)lo' hello to send to the server Debug => 1 Outputs via STDERR the conversation with the server
You have to pass AutoHello => 1, this will enable auto EHLO/HELO negotiation.
Passes test if the client does not connect to the SMTP Server. Everything after name is passed to the Net::SMTP_auth new method.
Passes if the last SMTP code returned by the server was expected.
Passes if the last SMTP code returned by the server was'nt expected.
Passes if the last SMTP code returned by the server indicates success.
Passes if the last SMTP code returned by the server doesn't indicate success.
Passes if the last SMTP code returned by the server indicates failure (either temporary or permanent).
Passes if the last SMTP code returned by the server doesn't indicate failure (either temporary or permanent).
Passes if the last SMTP code returned by the server indicates temporary failure
Passes if the last SMTP code returned by the server doesn't indicate temporary failure
Passes if the last SMTP code returned by the server indicates permanent failure
Passes if the last SMTP code returned by the server doesn't indicate permanent failure
Passes if the last SMTP message returned by the server matches the regex.
Passes if the last SMTP message returned by the server does'nt match the regex.
Passes if $user with $password with SASL method $method is AUTHorized on the server.
Passes if $user with $password with SASL method $method is not AUTHorized on the server.
Start TLS conversation with the server. Pass if server said that it's OK to start TLS and the SSL negotiation went OK.
Additional parameters will be passed to IO::Socket::SSL:
$smtp->starttls_ok('server presents correct certificate', SSL_verifycn_name => 'required-hostname.example.com', );
Start TLS conversation with the server. Pass if server said that it's not OK to start TLS or if the SSL negotiation failed.
Do EHLO/HELO negotiation. Useful only after starttls_ok/ko
Send a RSET command to the server. Pass if command was successful
Send an RSET to the server. Pass if command was not successful
Passes test if server said it supported capa capability on ESMTP EHLO
Passes test if server didn't say it supported capa capability on ESMTP EHLO
Compares server capa capability extra information with operator against expected.
Passes if server capa capability extra information matches against REGEX.
Passes if server capa capability extra information doesn't match against REGEX.
Passes if server banner matches against REGEX.
Passes if server banner doesn't match against REGEX.
Passes if server's announced domain matches against REGEX.
Passes if server's announced domain doesn't match against REGEX.
Sends a MAIL FROM: from to the server. Passes if the command succeeds
Sends a MAIL FROM: from to the server. Passes if the command isn't successful
Sends a RCPT TO: to to the server. Passes if the command succeeds
Sends a RCPT TO: to to the server. Passes if the command isn't successful
Sends a DATA command to the server. Passes if the command is successful. After calling this method, you should call datasend.
Sends a DATA command to the server. Passes if the command is'nt successful
Sends a .<CR><LF> command to the server. Passes if the command is successful.
Sends a .<CR><LF> command to the server. Passes if the command is not successful.
Sends HELP HELP_ON command to the server. If the returned text matches REGEX, the test passes. To test plain HELP command, pass undef in HELP_ON.
Sends HELP HELP_ON command to the server. If the returned text doesn't match REGEX, the test passes. To test plain HELP command, pass undef in HELP_ON.
Send a QUIT command to the server. Pass if command was successful
Send a QUIT command to the server. Pass if command was'nt successful
Issues a MAIL FROM: from command to the server.
Issues a RCPT TO: to command to the server.
Jose Luis Martinez CAPSiDE jlmartinez@capside.com http://www.pplusdomain.net/ http://www.capside.com/
Markus Benning (BENNING): Co-maintainer and code contributions
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
The full text of the license can be found in the LICENSE file included with this module.
Jose Luis Martinez <jlmartinez@capside.com>
This software is copyright (c) 2008 by Jose Luis Martinez.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.
To install Test::SMTP, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Test::SMTP
CPAN shell
perl -MCPAN -e shell install Test::SMTP
For more information on module installation, please visit the detailed CPAN module installation guide.