"Internal Server Error" when sending email via Django using DigitalOcean
When trying to send an email from a Django production setup (using gunicorn) on a Digitalocean droplet, I get "Internal Server Error" on the browser, and gunicorn logs this error:
…
File "/usr/lib/python3.13/smtplib.py", line 255, in __init__
(code, msg) = self.connect(host, port)
~~~~~~~~~~~~^^^^^^^^^^^^
File "/usr/lib/python3.13/smtplib.py", line 341, in connect
self.sock = self._get_socket(host, port, self.timeout)
~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/lib/python3.13/smtplib.py", line 312, in _get_socket
return socket.create_connection((host, port), timeout,
~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^
self.source_address)
^^^^^^^^^^^^^^^^^^^^
File "/usr/lib/python3.13/socket.py", line 849, in create_connection
sock.connect(sa)
~~~~~~~~~~~~^^^^
File "/usr/lib/python3.13/site-packages/gunicorn/workers/base.py", line 204, in handle_abort
sys.exit(1)
~~~~~~~~^^^
SystemExit: 1
This used to work without issues last year.
DigitalOcean has recently started blocking SMTP ports: https://docs.digitalocean.com/support/why-is-smtp-blocked/