Thursday, December 11, 2008

SMTP testing from the command line

To test SMTP from the command line:
  1. telnet host-to-test 25 (connect to port 25 on mail server)
  2. HELO sending-host
  3. MAIL FROM: foo@foo.com
  4. RCPT TO: bar@bar.com
  5. DATA
  6. (enter one blank line after DATA)
  7. Subject: test
    To: to-user
    From: from-user
    (enter one blank line after From:)
    test text for email
    . (enter a single period by itself on the last line)
  8. QUIT

Read on for testing servers that use SMTP AUTH...

To test SMTP with SMTP AUTH (no TLS/SSL) from the command line:

First, use a Perl one liner to compute the Base64 encoded user ID and password needed to authenticate to the mail server. This requires the Perl MIME::Base64 module.

perl -MMIME::Base64 -e 'print encode_base64("00userid00password")'

The output looks something like this:
AHVzZXJpZABwYXNzd29yZA==
Copy the output string so it can be pasted into the AUTH step below.

  1. telnet host-to-test 25 (connect to port 25 on mail server)
  2. HELO sending-host
  3. AUTH PLAIN Base64-encoded ID/password
  4. MAIL FROM: foo@foo.com
  5. RCPT TO: bar@bar.com
  6. DATA
  7. (enter one blank line after DATA)
  8. Subject: test
    To: to-user
    From: from-user
    (enter one blank line after From:)
    test text for email
    . (enter a single period by itself on the last line)
  9. QUIT