Troubleshooting using telnet

To troubleshoot mail client to mail server communications problems, it is often handy to connect to your mailserver manually using telnet. This will generally allow you to isolate basic problems to being:
- network connectivity, DNS or firewall related
- mail client related
- mail server related

The general approach will be to try and connect on the relevant ports (SMTP=25, POP=110, IMAP=143) and see whether you can connect and whether the server responds correctly when you send commands.

1) Check POP connectivity

[surgemail@linux]$ telnet smtp.netwin.co.nz 110
 Trying 216.65.64.228...
 Connected to smtp.netwin.co.nz.
 Escape character is '^]'.
 +OK POP3 netwin.co.nz (Version 3.8g-21) http://surgemail.com
 user myaccount@netwin.co.nz
 +OK myaccount@netwin.co.nz nice to hear from you - password required
 pass mypassword
 +OK myaccount has 1 mail messages
 list
 +OK 1 (1233)
 1 1233
 .
 retr 1
 +OK message follows
 Received: from testmail.com (1.2.3.4.bitstream.orcon.net.nz [1.2.3.4])
 by netwin.co.nz (SurgeMail 3.8g) with ESMTP id 5376645-1867996
 for <myaccount@netwin.co.nz>; Sun, 11 Mar 2007 16:40:08 -0700
 From: johnsmith@netwinsite.com
 To: myaccount@netwin.co.nz
 Subject: Test mail message
 Date: Sun, 11 Mar 2007 16:40:08 -0700
 Status: U
 Body of test message
 Some more body text
 The end of email
 .
 quit
 +OK closing connection
 Connection closed by foreign host.
  

Taking this step by step:

telnet smtp.netwin.co.nz 110
- If this fails with an error along the lines of: "Unknown host"
then you probably have an invalid DNS record or have a problem with your dns server
- If this fails with an error along the lines of: "Connection refused"
there is no connectivity to your server. Check your server is running, listening on the correct port, and there are no network problems, and no firewalls blocking communications. Provided surgemail is running, this problem is not related to surgemail.
- If it responds: "+OK POP3 netwin.co.nz"
then you have connectivity to the server, next try logging in via POP
user myaccount@netwin.co.nz
pass mypassword
- If this responds with "-ERR foo@netwin.co.nz password wrong or not a valid user"
then the username password combination is invalid for some reason. Check the account exists and the password is valid, the authentication module for correct configuration, next check surgemail mail.log files to see if these show any reason for failed logins.
- If there respond with "+OK myaccount has n mail messages"
then the login is valid on the server, try using the login with your mail client that you were previously having problems with.
list
retr 1
- This issues several POP commands (list available messages, retrieve first message) to confirm that the server is working correctly.

2) Check IMAP connectivity

Is is very similar to POP, but the port you use is different and the protocol is slightly different. An example follows:

[surgemail@linux]$ telnet smtp.netwin.co.nz 143
Trying 216.65.64.228...
Connected to smtp.netwin.co.nz.
Escape character is '^]'.
* OK IMAP netwin.co.nz (Version 3.8g-21)
A001 CAPABILITY
* CAPABILITY IMAP4 IMAP4REV1 NAMESPACE QUOTA UIDPLUS IDLE XFLDDATA SURGEMAIL STARTTLS
A001 OK CAPABILITY completed
A002 LOGIN "myaccount@netwin.co.nz" "mypassword"
A002 OK  LOGIN completed
A003 LIST "" "*"
* LIST () "/" INBOX
A020 OK LOGOUT completed
Connection closed by foreign host.
[surgemail@linux]$

3) Check SMTP connectivity

[surgemail@linux]$ telnet smtp.netwin.co.nz 25
Trying 216.65.64.228...
Connected to smtp.netwin.co.nz.
Escape character is '^]'.
220 netwin.co.nz SurgeSMTP (Version 3.8g-21) http://surgemail.com
HELO smtp.netwin.co.nz
MAIL FROM: <myaccount@netwin.co.nz>
RCPT TO: <johnsmith@netwin.co.nz>
DATA
From: myaccount@netwin.co.nz
To: johnsmith@netwin.co.nz
Subject: Test message

test message body
.
250 netwin.co.nz. Hello smtp.netwin.co.nz (1.2.3.4)
250 Command MAIL OK
250 local recipient ok
354 Command DATA Start mail input; end with .
250 message sent ok
quit
221 Command QUIT, disconnecting
Connection closed by foreign host.
[surgemail@linux]$

Again taking this step by step:

telnet smtp.netwin.co.nz 25
- If it responds: "220 netwin.co.nz SurgeSMTP"
then you have connectivity to the server, try sending mail
- If it responds with anything else troublshoot as for POP connections
HELO smtp.netwin.co.nz
MAIL FROM: <myaccount@netwin.co.nz>
RCPT TO: <johnsmith@netwin.co.nz>
DATA
From: myaccount@netwin.co.nz
To: johnsmith@netwin.co.nz
Subject: Test message

test bmessage body
.

- If after entering the above the response is "250 message sent ok" then you can send mail through the server. Now try sending mail through your mail client.
- If the response is "relaying blocked, read new mail, add 1.2.3.4 to forwarding or enable smtp authentication" then you need to test this using your mail client with "authentication when sending mail" enabled.
- It is also possible you will receive one of various spam prevention reject responses.

 

4) Check WEB connectivity

It is not quite as useful to test web connectivity using telnet, but you can use the same technique to make sure you have connectivity:

[surgemail@linux]$ telnet smtp.netwin.co.nz 80
Trying 216.65.64.228...
Connected to smtp.netwin.co.nz.
Escape character is '^]'.
GET / HTTP/1.1
HTTP/1.0 200 OK Server: DManager MIME-version: 1.0 Date: Mon, 12 Mar 2007 00:52:36 GMT Content-type: text/html <!doctype html public "-//w3c//dtd html 4.0 transitional//en"> <html> <head> <title>SurgeMail Welcome Page</title> .... </body> </html> Connection closed by foreign host.