title: How can I automate telnet port 25 testing?
body: <p>I need to make a large set of tests in telnet.  I am working on some ways to auto detect dictionary attacks on our email server, and then throttle them back, or blacklist them etc.</p>
  <p>I am now ready to run some tests and see if my work pays off.  I figured I would just download some script kiddy app to run the tests. I can not find any and those I can are bad or binary and non configurable.</p>
  <p>I will have a list of addresses I generate in a loop.</p>
  <p>I want to take $address as an argument and do this:</p>
  <blockquote>
  <p>telnet myserver.com 25
  helo some-string.com
  mail from: me@me.com
  rcpt to: $address
  quit</p>
  </blockquote>
  <p>Within that, I need to test a few things, such as, if I enable greylisting, I want to fail the script, as that is my first countermeasure.  I suppose in that case, I would just have telnet timeout?</p>
  <ul>
  <li><p><code>helo</code> should return a code string starting with 220, that is about as accurate as I need to make this test.</p>
  </li>
  <li><p><code>mail from</code> should return 250, or looking for OK would suffice</p>
  </li>
  <li><p><code>rctp to</code> should return 250 or Ok sometimes, when I send in a valid user, but most of the time I will send in a bad address, so I look for the absence of 250 or OK.</p>
  </li>
  <li><p>Finally, I will send in a <code>quit</code>.</p>
  </li>
  </ul>
  <p>I am not able to get conditions and logging to happen within an interactive situation.  I looked at <code>expect</code> but could not get it to work.</p>
  <h3>My code so far:</h3>
  <pre><code>echo -e &quot;helo foo\nmail from: foo.... | telnet example.com 25 | grep -i blah 
  </code></pre>
  <p>This did not perform as expected.</p>
  <p>What can I do to accomplish my goal?</p>