title: bash and telnet to test an email
body: <p>I'm trying to find out whether an email address is valid.</p>
  
  <p>I've accomplished this by usign telnet, see below</p>
  
  <pre><code>$ telnet mail.example.com 25
  Trying 0.0.0.0...
  Connected to mail.example.com.
  Escape character is '^]'.
  220 mail.example.com Mon, 14 Jan 2013 19:01:44 +0000
  helo email.com
  250 mail.example.com Hello email.com [0.0.0.0]
  mail from:blake@email.com
  250 OK
  rcpt to:gfdgsdfhgsfd@example.com
  550 Unknown user
  </code></pre>
  
  <p>with this 550 request i know that the address is not valid on the mail server... if it was valid i would get a response like the below:</p>
  
  <pre><code>250 2.1.5 OK 
  </code></pre>
  
  <p>How would I automate this in a shell script? so far I have the below</p>
  
  <pre><code>#!/bin/bash
  host=`dig mx +short $1 | cut -d ' ' -f2 | head -1`
  telnet $host 25 
  </code></pre>
  
  <p>Thanks!</p>