title: Python SMTPlib Error 111 Connection Refused?
body: <p>I was using Gmail to send some emails through a program I have hosted on PythonAnywhere with SMTPlib.. It is a single user program so I thought this would work fine. However I am running into security issues with Gmail where it will sometimes block the login and not send the mail. So I decided to switch, because I have a website on Hostgator and figured I could just send it through there.. However I am now getting an Error 111 Connection Refused response when trying to send mail. I know for a fact the username/password and SMPT setting are exactly what HostGator recommends for a manual setup..</p>
  
  <pre><code>def sendmail(toaddr, msg):
      fromaddr = 'john@usmith.com'
      cc = 'chris@*************.com'
      msg['Cc'] = cc
      server = smtplib.SMTP('gator3119.hostgator.com', 465)
      server.login(fromaddr, "*******")
      text = msg.as_string()
      server.sendmail(fromaddr, [toaddr, cc], text)
      server.quit()
  </code></pre>
  
  <p>Here is the full trace-back</p>
  
  <pre><code>2017-02-13 11:31:40,274 :ConnectionRefusedError: [Errno 111] Connection refused
       File "/usr/local/lib/python3.5/dist-packages/flask/app.py", line 1836, in __call__
  2017-02-13 11:31:40,274 :    return self.wsgi_app(environ, start_response)
  2017-02-13 11:31:40,274 :
  2017-02-13 11:31:40,274 :  File "/usr/local/lib/python3.5/dist-packages/flask/app.py", line 1820, in wsgi_app
  2017-02-13 11:31:40,274 :    response = self.make_response(self.handle_exception(e))
  2017-02-13 11:31:40,274 :
  2017-02-13 11:31:40,274 :  File "/usr/local/lib/python3.5/dist-packages/flask/app.py", line 1403, in handle_exception
  2017-02-13 11:31:40,274 :    reraise(exc_type, exc_value, tb)
  2017-02-13 11:31:40,275 :
  2017-02-13 11:31:40,275 :  File "/usr/local/lib/python3.5/dist-packages/flask/_compat.py", line 33, in reraise
  2017-02-13 11:31:40,275 :    raise value
  2017-02-13 11:31:40,275 :
  2017-02-13 11:31:40,275 :  File "/usr/local/lib/python3.5/dist-packages/flask/app.py", line 1817, in wsgi_app
  2017-02-13 11:31:40,275 :    response = self.full_dispatch_request()
  2017-02-13 11:31:40,275 :
  2017-02-13 11:31:40,275 :  File "/usr/local/lib/python3.5/dist-packages/flask/app.py", line 1477, in full_dispatch_request
  2017-02-13 11:31:40,275 :    rv = self.handle_user_exception(e)
  2017-02-13 11:31:40,275 :
  2017-02-13 11:31:40,275 :  File "/usr/local/lib/python3.5/dist-packages/flask/app.py", line 1381, in handle_user_exception
  2017-02-13 11:31:40,275 :    reraise(exc_type, exc_value, tb)
  2017-02-13 11:31:40,275 :
  2017-02-13 11:31:40,275 :  File "/usr/local/lib/python3.5/dist-packages/flask/_compat.py", line 33, in reraise
  2017-02-13 11:31:40,275 :    raise value
  2017-02-13 11:31:40,275 :
  2017-02-13 11:31:40,276 :  File "/usr/local/lib/python3.5/dist-packages/flask/app.py", line 1475, in full_dispatch_request
  2017-02-13 11:31:40,276 :    rv = self.dispatch_request()
  2017-02-13 11:31:40,276 :
  2017-02-13 11:31:40,276 :  File "/usr/local/lib/python3.5/dist-packages/flask/app.py", line 1461, in dispatch_request
  2017-02-13 11:31:40,276 :    return self.view_functions[rule.endpoint](**req.view_args)
  2017-02-13 11:31:40,276 :
  2017-02-13 11:31:40,276 :  File "/home/chrisutpg/utpp/UTPP/notes.py", line 29, in addnote
  2017-02-13 11:31:40,276 :    sendNote(noteInfo, clientInfo)
  2017-02-13 11:31:40,276 :
  2017-02-13 11:31:40,276 :  File "/home/chrisutpg/utpp/UTPP/uttpemail.py", line 192, in sendNote
  2017-02-13 11:31:40,276 :    sendmail(toaddr, msg)
  2017-02-13 11:31:40,276 :
  2017-02-13 11:31:40,276 :  File "/home/chrisutpg/utpp/UTPP/uttpemail.py", line 16, in sendmail
  2017-02-13 11:31:40,276 :    server = smtplib.SMTP('gator3119.hostgator.com', 465)
  2017-02-13 11:31:40,276 :
  2017-02-13 11:31:40,277 :  File "/usr/lib/python3.5/smtplib.py", line 251, in __init__
  2017-02-13 11:31:40,277 :    (code, msg) = self.connect(host, port)
  2017-02-13 11:31:40,277 :
  2017-02-13 11:31:40,277 :  File "/usr/lib/python3.5/smtplib.py", line 335, in connect
  2017-02-13 11:31:40,277 :    self.sock = self._get_socket(host, port, self.timeout)
  2017-02-13 11:31:40,277 :
  2017-02-13 11:31:40,277 :  File "/usr/lib/python3.5/smtplib.py", line 306, in _get_socket
  2017-02-13 11:31:40,277 :    self.source_address)
  2017-02-13 11:31:40,277 :
  2017-02-13 11:31:40,277 :  File "/usr/lib/python3.5/socket.py", line 711, in create_connection
  2017-02-13 11:31:40,277 :    raise err
  2017-02-13 11:31:40,277 :
  2017-02-13 11:31:40,277 :  File "/usr/lib/python3.5/socket.py", line 702, in create_connection
  2017-02-13 11:31:40,277 :    sock.connect(sa)
  </code></pre>
  
  <p>Any ideas why this would not work as desired? I've also tried using the Non-Secure settings for HostGator and got the same error response.</p>
  
  <p><a href="https://i.stack.imgur.com/SvBpY.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/SvBpY.png" alt="enter image description here"></a></p>