Use Expect for SMTP testing

July 10, 2008

I learned about Expect from a past ADC video session about OS X deployment. Here’s a very practical use for it - testing an SMTP server. Just run it with expect filename.

spawn telnet smtpserver 25
expect "220 "
send "MAIL\r"
expect "250 Ok$"
send "RCPT TO:testuser@server\r"
expect "250 Ok$"
send "DATA\r"
expect "354"
send "From: "SMTP Test" <>
Subject: This is a test
Date: Wed, 02 Jul 2008 15:08:43 +0000
Body of test message r.\r"
expect "250 Ok$"
send "QUIT\r"