I am running a lightweight SMTP server for processing incoming emails. I am using https://github.com/kennethreitz/inbox.py. I opened port 25 in my firewall and am running the server at

Everything is functioning as I expect. When I send email to name@mydomain.com the server receives the message.

The thing that is strange to me is that when I telnet to port 25 from outside the VPS, it does not connect and times out:

$ telnet mydomain.com 25
Trying <IP address removed>...
telnet: connect to address <IP address removed>: Operation timed out
telnet: Unable to connect to remote host

When I telnet from inside the VPS, it works as it should:

$ telnet localhost 25
Trying ::1...
Connected to localhost.
Escape character is '^]'.
220 hobnob Python SMTP proxy version 0.2

I cannot think of any reason why this happening. What could it be?


I was able to establish a connection using a Python shell:

from smtplib import SMTP
conn = SMTP('mydomain.com')

I confirmed that this will fail if the server is not running. It seems maybe that telnet cannot make the connection correctly? I'm not sure, but it is clear that connections can be made to the server by email software which is what I was really trying to test.


There are quite a few reasons for this.

It may be that port 25 is being blocked by your VPS provider. Many will require that you specifically ask that it be opened, to help cut down on spam.

Also, your firewall might be blocking port 25 inbound traffic. Get rid of that.

The other common thing is listening only on localhost, though because you have set as the binding address that shouldn't be the problem.

Often, incoming mail will come in through some other port (particularly, submission on port 587), so you may still get mail with port 25 blocking around.

| improve this answer | |
  • Since the application is working, we know that the VPS provider is not blocking port 25 and nor is my firewall. The firewall is blocking port 587. I think I may have found a clue though. See my update. – hekevintran Jul 8 '13 at 21:49
  • It could also be blocked outgoing from wherever you are testing from. – Falcon Momot Jul 8 '13 at 22:39
  • Possibly, but in that case, the Python code shouldn't be able to connect right? – hekevintran Jul 8 '13 at 23:14
  • It isn't clear from the information you have provided. However, telnet is a pretty accurate test for the ability to open a TCP connection. Port 465 is also sometimes used for SMTP (specifically with SSL) though I believe that is deprecated. – Falcon Momot Jul 8 '13 at 23:23

Have you checked the DNS MX records for "mydomain.com"? For example:

dig +short mydomain.com MX

Do this check both inside and outside your VPS: the results may differ.

Your VPS provider may have arranged for incoming external email to enter through their central mail relay servers. This allows them to set up protections against malware and other abuse on behalf of the users. (It can also allow for other things, but that's what email encryption is for.) Once the mail has passed through the provider's server, it will be automatically forwarded to your system.

If such a relay system has been set up, then direct access to port 25 of your VPS from the internet may have been blocked.

Python smtplib might be smart enough to automatically check for MX records and automatically connect to the indicated relay server(s) instead of directly to your own server. Telnet definitely won't.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.