Skip to content

Mistake in the instructions for setting up SMTP

Summary

Comment in dogmap/init.py on line 77 states that the environment variable for GMAIL_SMTP_HOST is smtp.google.com, but it should actually be smtp.gmail.com.

Steps to reproduce

Place GMAIL_SMTP_HOST="smtp.google.com" in .env

What is the current bug behavior?

Using the incorrect host causes a timeout and a connection error when the server tries to send an email.

What is the expected correct behavior?

Email is sent.

Relevant logs and/or screenshots

Traceback

Traceback (most recent call last):
  File "/home/vscode/.local/lib/python3.9/site-packages/werkzeug/serving.py", line 324, in run_wsgi
    execute(self.server.app)
  File "/home/vscode/.local/lib/python3.9/site-packages/werkzeug/serving.py", line 313, in execute
    application_iter = app(environ, start_response)
  File "/home/vscode/.local/lib/python3.9/site-packages/sentry_sdk/integrations/flask.py", line 90, in sentry_patched_wsgi_app
    return SentryWsgiMiddleware(lambda *a, **kw: old_app(self, *a, **kw))(
  File "/home/vscode/.local/lib/python3.9/site-packages/sentry_sdk/integrations/wsgi.py", line 140, in __call__
    reraise(*_capture_exception(hub))
  File "/home/vscode/.local/lib/python3.9/site-packages/sentry_sdk/_compat.py", line 54, in reraise
    raise value
  File "/home/vscode/.local/lib/python3.9/site-packages/sentry_sdk/integrations/wsgi.py", line 133, in __call__
    rv = self.app(
  File "/home/vscode/.local/lib/python3.9/site-packages/sentry_sdk/integrations/flask.py", line 90, in <lambda>
    return SentryWsgiMiddleware(lambda *a, **kw: old_app(self, *a, **kw))(
  File "/home/vscode/.local/lib/python3.9/site-packages/flask/app.py", line 2091, in __call__
    return self.wsgi_app(environ, start_response)
  File "/home/vscode/.local/lib/python3.9/site-packages/flask/app.py", line 2076, in wsgi_app
    response = self.handle_exception(e)
  File "/home/vscode/.local/lib/python3.9/site-packages/flask/app.py", line 2073, in wsgi_app
    response = self.full_dispatch_request()
  File "/home/vscode/.local/lib/python3.9/site-packages/flask/app.py", line 1518, in full_dispatch_request
    rv = self.handle_user_exception(e)
  File "/home/vscode/.local/lib/python3.9/site-packages/flask/app.py", line 1516, in full_dispatch_request
    rv = self.dispatch_request()
  File "/home/vscode/.local/lib/python3.9/site-packages/flask/app.py", line 1502, in dispatch_request
    return self.ensure_sync(self.view_functions[rule.endpoint])(**req.view_args)
  File "/workspaces/tjts5901-dogmap_template/dogmap/authentication.py", line 195, in user_login
    send_authorization_link(user, _email)
  File "/workspaces/tjts5901-dogmap_template/dogmap/authentication.py", line 152, in send_authorization_link
    r = mailer_smtp([message])
  File "/workspaces/tjts5901-dogmap_template/dogmap/authentication.py", line 108, in mailer_smtp
    with SMTP(host=smtp_host, port=smtp_port) as smtp:
  File "/usr/local/lib/python3.9/smtplib.py", line 255, in __init__
    (code, msg) = self.connect(host, port)
  File "/usr/local/lib/python3.9/smtplib.py", line 341, in connect
    self.sock = self._get_socket(host, port, self.timeout)
  File "/usr/local/lib/python3.9/smtplib.py", line 312, in _get_socket
    return socket.create_connection((host, port), timeout,
  File "/usr/local/lib/python3.9/socket.py", line 844, in create_connection
    raise err
  File "/usr/local/lib/python3.9/socket.py", line 832, in create_connection
    sock.connect(sa)
OSError: [Errno 99] Cannot assign requested address

Possible fixes

Simply change the instruction from using smtp.google.com to smtp.gmail.com instead to prevent others from encountering the same error.