Python smtplib: Why is the connection refused?
Question: So, in the Python interpreter, I do this (and only this):

    
    
    >>> import smtplib
    >>> s=smtplib.SMTP("localhost")
    

And this is what I get:

    
    
    Traceback (most recent call last):
        File "<stdin>", line 1, in <module>
        File "/usr/lib/python3.4/smtplib.py", line 242, in __init__
        (code, msg) = self.connect(host, port)
        File "/usr/lib/python3.4/smtplib.py", line 321, in connect
        self.sock = self._get_socket(host, port, self.timeout)
        File "/usr/lib/python3.4/smtplib.py", line 292, in _get_socket
        self.source_address)
        File "/usr/lib/python3.4/socket.py", line 509, in create_connection
        raise err
        File "/usr/lib/python3.4/socket.py", line 500, in create_connection
        sock.connect(sa)
    ConnectionRefusedError: [Errno 111] Connection refused
    

Does anyone have any ideas as to why am I getting this error? (That's my
question.) It's not supposed to do that from what I understand. Tell me if I'm
wrong.

I'm using Xubuntu 14.04. If you need more information, please ask. I don't
know of anything else I can tell you, off-hand.

Thanks!


Answer: SMTPlib is going to try to connect to an SMTP service, usually running on port
25, though it can run on various other ports. Sounds like maybe you need to
install sendmail, postfix, or something of that nature.

