SMTP server works, but telnet to port 25 does not

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 0.0.0.0:25.

Everything is functioning as I expect. When I send email to [email protected] 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...
Trying 127.0.0.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?

UPDATE:

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.


Solution 1:

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 0.0.0.0 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.