#!/usr/bin/expect -f spawn telnet amnesiac.heapspace.net 25 expect { 220 { send "HELO test.host\n" } timeout { send_user "Timed out connecting to host" abort } } expect { 250 { send "MAIL FROM: \n" } timeout { send_user "Timed out at MAIL FROM" abort } default { send_user "Something bad happened - aborting" abort } } expect { 250 { send "RCPT TO: \n" } default { send_user "Something bad happened - aborting" abort } } expect { 250 { send "DATA\n" } default { send_user "Something bad happened - aborting" abort } } expect { 354 { send "From: Brett Parker \n" send "To: Brett Parker \n" send "Subject: Test Mail\n" send "\n\n" } default { send_user "Didn't get a 354 - giving up" abort } } send [exec cat test.txt] send "\r\n.\r\n" expect { 250 { send_user "All done." exit } default { send_user "It broke, bah." abort } }