Mailfromd Manual (split by node):   Section:   Chapter:FastBack: mtasim   Up: mtasim   FastForward: pmult   Contents: Table of ContentsIndex: Concept Index

12.2 mtasim expect commands

Until now we were using mtasim interactively. However, it is often useful in shell scripts, for example the mailfromd test suite is written in shell and mtasim. To avoid the necessity to use auxiliary programs like expect or DejaGNU, mtasim contains a built-in expect feature. The administrative command \E introduces the SMTP code that the next command is expected to yield. For example,

\E250
rcpt to: <foo@bar.org>

tells mtasim that the response to RCPT TO command must begin with ‘250’ code. If it does, mtasim continues execution. Otherwise, it prints an error message and terminates with exit code 1. The error message it prints looks like:

Expected 250 but got 470

The expect code given with the \E command may have less than 3 digits. In this case it specifies the first digits of expected reply. For example, the command ‘\E2’ matches replies ‘200’, ‘220’, etc.

This feature can be used to automate your tests. For example, the following script tests the greylisting functionality (see the previous section):

# Test the greylisting functionality
#
\E220
\Dclient_addr=10.10.1.13
\E250
ehlo yahoo.com
\E250
mail from: <gray@yahoo.com>
\E450
rcpt to: <gray@localhost>
\E221
quit

This example also illustrates the fact that you can use ‘#’-style comments in the mtasim input. Such a script can be used in shell programs, for example:

mtasim -Xauto --statedir -- -I. -I../mflib test.rc < scriptfile
if $? -ne 0; then
  echo "Greylisting test failed"
fi

Mailfromd Manual (split by node):   Section:   Chapter:FastBack: mtasim   Up: mtasim   FastForward: pmult   Contents: Table of ContentsIndex: Concept Index