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.
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.
Have you checked the DNS MX records for "mydomain.com"? For example:
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.