SamR1/FitTrackee

Cannot send mails

Closed this issue · 7 comments

I’ve some troubles sending mails from my FitTrackee instance.

Whenever I try it, I have:

Traceback (most recent call last):
  File "/var/www/fittrackee__2/venv/lib/python3.9/site-packages/dramatiq/worker.py", line 485, in process_message
    res = actor(*message.args, **message.kwargs)
  File "/var/www/fittrackee__2/venv/lib/python3.9/site-packages/dramatiq/actor.py", line 177, in __call__
    return self.fn(*args, **kwargs)
  File "/var/www/fittrackee__2/venv/lib/python3.9/site-packages/fittrackee/emails/tasks.py", line 48, in account_confirmation_email
    email_service.send(
  File "/var/www/fittrackee__2/venv/lib/python3.9/site-packages/fittrackee/emails/email.py", line 173, in send
    smtp.login(self.username, self.password)  # type: ignore
  File "/usr/lib/python3.9/smtplib.py", line 700, in login
    raise SMTPNotSupportedError(
smtplib.SMTPNotSupportedError: SMTP AUTH extension not supported by server.

My .env file is as follow:

# Custom variables initialisation
# (can overwrite variables present in Makefile.config)

# Application
FLASK_APP=fittrackee
FLASK_SKIP_DOTENV=1
# HOST=
PORT=__PORT__
# APP_SETTINGS=fittrackee.config.ProductionConfig
APP_SECRET_KEY='__KEY__'
# APP_WORKERS=
APP_LOG=/var/log/__APP__/__APP__.log
UPLOAD_FOLDER=__DATA_DIR__

# PostgreSQL
DATABASE_URL=postgresql://__DB_USER__:__DB_PWD__@:5432/__DB_NAME__
# DATABASE_DISABLE_POOLING=

# Redis (required for API rate limits and email sending)
REDIS_URL=redis://

# API rate limits
# API_RATE_LIMITS="300 per 5 minutes"

# Emails
UI_URL=__DOMAIN__
EMAIL_URL=smtp://__APP__:__MAIL_PWD__@127.0.0.1:25
SENDER_EMAIL=__APP__@__DOMAIN__
# WORKERS_PROCESSES=

# Workouts
TILE_SERVER_URL=https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png
MAP_ATTRIBUTION='&copy; <a href="http://www.openstreetmap.org/copyright" target="_blank" rel="noopener noreferrer">OpenStreetMap</a> contributors'
DEFAULT_STATICMAP=False
STATICMAP_SUBDOMAINS=''

# Weather
# available weather API providers: darksky, visualcrossing
WEATHER_API_PROVIDER=__WEATHER_PROVIDER__
WEATHER_API_KEY=__WEATHER_KEY__

It’s the config for Yunohost so everything is in bash/shell.

Do you have an idea what the issue is?

Thanks in advance!

SamR1 commented

Hi,

Maybe the SMTP server does not support authentication with unencrypted connection (port 25).
Can you try with SSL (port 465)?

Thank you, I’m still discovering all these email things…

With port 465:

Traceback (most recent call last):
  File "/var/www/fittrackee__2/venv/lib/python3.9/site-packages/dramatiq/worker.py", line 485, in process_message
    res = actor(*message.args, **message.kwargs)
  File "/var/www/fittrackee__2/venv/lib/python3.9/site-packages/dramatiq/actor.py", line 177, in __call__
    return self.fn(*args, **kwargs)
  File "/var/www/fittrackee__2/venv/lib/python3.9/site-packages/fittrackee/emails/tasks.py", line 48, in account_confirmation_email
    email_service.send(
  File "/var/www/fittrackee__2/venv/lib/python3.9/site-packages/fittrackee/emails/email.py", line 165, in send
    with self.smtp(
  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 1040, in _get_socket
    new_socket = super()._get_socket(host, port, timeout)
  File "/usr/lib/python3.9/smtplib.py", line 310, in _get_socket
    return socket.create_connection((host, port), timeout,
  File "/usr/lib/python3.9/socket.py", line 843, in create_connection
    raise err
  File "/usr/lib/python3.9/socket.py", line 831, in create_connection
    sock.connect(sa)
ConnectionRefusedError: [Errno 111] Connection refused

And with 587:

Traceback (most recent call last):
  File "/var/www/fittrackee__2/venv/lib/python3.9/site-packages/dramatiq/worker.py", line 485, in process_message
    res = actor(*message.args, **message.kwargs)
  File "/var/www/fittrackee__2/venv/lib/python3.9/site-packages/dramatiq/actor.py", line 177, in __call__
    return self.fn(*args, **kwargs)
  File "/var/www/fittrackee__2/venv/lib/python3.9/site-packages/fittrackee/emails/tasks.py", line 48, in account_confirmation_email
    email_service.send(
  File "/var/www/fittrackee__2/venv/lib/python3.9/site-packages/fittrackee/emails/email.py", line 170, in send
    smtp.starttls(context=context)
  File "/usr/lib/python3.9/smtplib.py", line 774, in starttls
    self.sock = context.wrap_socket(self.sock,
  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.SSLCertVerificationError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: IP address mismatch, certificate is not valid for '127.0.0.1'. (_ssl.c:1123)
SamR1 commented

Thanks for the logs.

I'm not familiar with emails setup on Yunohost instance.
Can you try with the domain configured for the SMTP server (instead of 127.0.0.1) and port 587?
If the certificate is self-signed, it may not work.

Sorry for the delay!

Can you try with the domain configured for the SMTP server (instead of 127.0.0.1) and port 587?

Traceback (most recent call last):
  File "/var/www/fittrackee__2/venv/lib/python3.9/site-packages/dramatiq/worker.py", line 485, in process_message
    res = actor(*message.args, **message.kwargs)
  File "/var/www/fittrackee__2/venv/lib/python3.9/site-packages/dramatiq/actor.py", line 177, in __call__
    return self.fn(*args, **kwargs)
  File "/var/www/fittrackee__2/venv/lib/python3.9/site-packages/fittrackee/emails/tasks.py", line 48, in account_confirmation_email
    email_service.send(
  File "/var/www/fittrackee__2/venv/lib/python3.9/site-packages/fittrackee/emails/email.py", line 173, in send
    smtp.login(self.username, self.password)  # type: ignore
  File "/usr/lib/python3.9/smtplib.py", line 734, in login
    raise last_exception
  File "/usr/lib/python3.9/smtplib.py", line 723, in login
    (code, resp) = self.auth(
  File "/usr/lib/python3.9/smtplib.py", line 646, in auth
    raise SMTPAuthenticationError(code, resp)
smtplib.SMTPAuthenticationError: (535, b'5.7.8 Error: authentication failed: UGFzc3dvcmQ6')

I will see if I can ask some Yunohost packagers to have a look too 👀

SamR1 commented

Hi,

No problem :).

It seems that the error is now related to authentication. Can you check the credentials in .env?

Okay, it seems it’s a bug in Yunohost. Devs are working on a fix!

Sorry for disturbing here: after checking with my own email address, may worked well. Thanks for your great job!! 🤩

For the sake of completeness, here is the fix in Yunohost (just released).
It was a problem with some ipv6 config (YunoHost/yunohost#1710).