Monday, June 21, 2010

Testing SMTP

Sometimes it's important to be able to manually reproduce what your computer/server is doing manually so you can see exactly where it's failing. Troubleshooting "utilities" are great in that they can often diagnose hundreds of issues in less time than it would take you to troubleshoot one, but they lack the nuance sometimes necessary to accurately diagnose issues.

A simple pass/fail is nice, but if you don't know WHY it's failing, what good is it?

When troubleshooting email, there are websites, utilities, diagnostic messages and more designed to help figure out what's going wrong. I have never found a single one that has been more informative than a simple SMTP session.

If you have telnet on your computer, that'll work fine. Netcat or any other command line tool that you can specify the ports to connect on will work too.

On your command/shell prompt type: telnet <the server's IP> 25

Then, when prompted, type the following commands:

---------------------------------------------------------------------------
HELO your hostname
<wait for response>
MAIL FROM: <your email address>
<wait for response>
RCPT TO: <recipient'semail address>
<wait for response>
DATA
<wait for response>
FROM: <your email address>
TO: <recipient'semail address>
SUBJECT: test

this is a test.
.

----------------------------------------------------------------

Note the additional CR/LF after the subject. That separates the headers from the body (visible part) of the message. It's very important.

Also important is the line with a "." by itself. This tells the recipient's server that the message is complete and to process it.

On to troubleshooting....

In each part above where it says "wait for a response" you're expecing a response from the server, either something like "ok, go ahead", an error, or sometimes nothing. Here are some examples:

HELO

If there's no response, this can indicate that the server is extremely busy or that sometimes there's packet filtration between you and the server that's intercepting and silently dropping the packets. Either way, if there's no response, there's no transmission, and therefore no email.

Sometimes you'll get an error here referencing that it does not like your IP (if you're blacklisted), or that it's imposing some type of lookup on your HELO argument. It's best to be sure thet you give your FQDN here to prevent issues.

MAIL FROM:

You might get SPF errors here if your SPF record is wrong, or if your email address is blacklisted you might get a response here.

RCPT TO:

"Relaying denied", "mailbox is full", or any number of other recipient level issues may result as a response to this line. Any server that has different rules per user or domain (like a shared spam filter with different settings per domain/user) might also process here.

DATA

You're now giving the actual data that will be shown to the user. Generally there won't be an issue here until you close the transmission channel (with the "." on a line by itself), but anywhere you wait for a response is a potential place for errors.

"." (or closing the transmission channel)

This is where the email in it's entirety can be scanned and processed. Sometimes nothing will be scanned until this point, so even though SPF *could* be looked up after the "mail from:" command, it *might* not be until the entire message has been transmitted. Any of the above errors can happen here as well as content based scanning of the body, etc.

Some mail servers will also accept the email here, and then scan it later before delivery. That's a horrible idea, but that doesn't stop anyone usually, so be sure to copy down any information the acceptance line gives you like the message ID, so you can reference it later if the test does not complete.

Generally, you'll only be able to run this test on a border MTA unless it's your own mail server or the recipient's firewall allows you through. This can definitely complicate troubleshooting, but if you can prove that the issue is with the border MTA, or that the border MTA accepts the email but it is not relayed it at least absolves you from any finger pointing.

Once you have these commands memorized (it doesn't take long), you'll often be able to troubleshoot and diagnose issues faster than submitting tickets to your vendors. There's nothing more frustrating than either waiting for a response only to find out you could have fixed it hours ago, or conversely that you know exactly where the error occurred, but the other admin requires "proof" that they should bother fixing the issue when the DSN or other logs obviously state the issue.

Send a couple SMTP sessions their way and copy the session to them. It's hard to argue with facts :-)


-TEA

1 comment :

  1. I want to know the location of one of my mail sendor id ellamadona368@gmail.com

    ReplyDelete