Add a SMTP_USE_SSL config option
while working on tpo/tpa/team#41034 (closed), i configured tor-weather's SMTP settings to use the postfix server on localhost:25
, which doesn't seem to have SSL (which is fine because it's an internal-only SMTP server). Registering for a new account threw this traceback:
Initiating SMTP Connection
localhost 25
[2023-02-02 20:35:17,864] ERROR in app: Exception on /api/register [POST]
Traceback (most recent call last):
File "/home/weather/.tor-weather-virtualenv/lib/python3.9/site-packages/flask/app.py", line 1517, in full_dispatch_request
rv = self.dispatch_request()
File "/home/weather/.tor-weather-virtualenv/lib/python3.9/site-packages/flask/app.py", line 1503, in dispatch_request
return self.ensure_sync(self.view_functions[rule.endpoint])(**req.view_args)
File "/home/weather/.tor-weather-virtualenv/lib/python3.9/site-packages/flask_restx/api.py", line 405, in wrapper
resp = resource(*args, **kwargs)
File "/home/weather/.tor-weather-virtualenv/lib/python3.9/site-packages/flask/views.py", line 84, in view
return current_app.ensure_sync(self.dispatch_request)(*args, **kwargs)
File "/home/weather/.tor-weather-virtualenv/lib/python3.9/site-packages/flask_restx/resource.py", line 46, in dispatch_request
resp = meth(*args, **kwargs)
File "/home/weather/tor-weather/src/resources/external_api_routes/register_user.py", line 32, in post
return User().register(email, password)
File "/home/weather/tor-weather/src/service/user.py", line 128, in register
self._send_email_verification_code(email)
File "/home/weather/tor-weather/src/service/user.py", line 85, in _send_email_verification_code
Smtp().send_mail(mail_content)
File "/home/weather/tor-weather/src/core/smtp/app.py", line 52, in send_mail
self._initiate_connection()
File "/home/weather/tor-weather/src/core/smtp/app.py", line 22, in _initiate_connection
self.smtp = smtplib.SMTP_SSL(self.host, self.port)
File "/usr/lib/python3.9/smtplib.py", line 1034, in __init__
SMTP.__init__(self, host, port, local_hostname, timeout,
File "/usr/lib/python3.9/smtplib.py", line 253, in __init__
(code, msg) = self.connect(host, port)
File "/usr/lib/python3.9/smtplib.py", line 339, in connect
self.sock = self._get_socket(host, port, self.timeout)
File "/usr/lib/python3.9/smtplib.py", line 1041, in _get_socket
new_socket = self.context.wrap_socket(new_socket,
File "/usr/lib/python3.9/ssl.py", line 500, in wrap_socket
return self.sslsocket_class._create(
File "/usr/lib/python3.9/ssl.py", line 1040, in _create
self.do_handshake()
File "/usr/lib/python3.9/ssl.py", line 1309, in do_handshake
self._sslobj.do_handshake()
ssl.SSLError: [SSL: WRONG_VERSION_NUMBER] wrong version number (_ssl.c:1123)
i think the quickest way to fix this would be to add a SMTP_USE_SSL
environment variable that defaults to True
, and changes whether smtplib uses SSL or not. i know python's ssl configuration can be difficult to deal with, so if this is too big an ask for right now we can work around it by adding a role user to the submission server.
/cc @sarthikg
Edited by Kez