Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Email_backend not configured despite environment variable being set #7436

Closed
2 tasks done
Farenweh opened this issue Feb 4, 2024 · 16 comments
Closed
2 tasks done

Email_backend not configured despite environment variable being set #7436

Farenweh opened this issue Feb 4, 2024 · 16 comments
Labels
question Further information is requested

Comments

@Farenweh
Copy link

Farenweh commented Feb 4, 2024

Actions before raising this issue

  • I searched the existing issues and did not find anything similar.
  • I read/searched the docs

Steps to Reproduce

0: Deploy CVAT step by step under the guidence of official Docs, with Docker and on Ubuntu;
1: Modify docker-compose.yml, like this:

cvat_server:
    container_name: cvat_server
    image: cvat/server:${CVAT_VERSION:-dev}
    ......
    environment:
      <<: *backend-env
      ......
      # fixme email
      EMAIL_HOST: smtp.qq.com
      EMAIL_PORT: 465
      EMAIL_USE_SSL: True
      EMAIL_HOST_USER: 123456789@qq.com
      EMAIL_HOST_PASSWORD: EMAIL_HOST_PASSWORD
      # EMAIL_BACKEND: 'django.core.mail.backends.smtp.EmailBackend' # Tried but 
      EMAIL_BACKEND : 'django.core.mail.backends.console.EmailBackend' 
      ......

2: Create an orgnization and invite a guy, try sending an email.
3: Fail to send and get “Email backend is not configured.”

I have confirmed that the environment variable is set correctly inside the Docker container by using the command printenv | grep EMAIL_BACKEND, which returns the expected output: EMAIL_BACKEND=django.core.mail.backends.console.EmailBackend.
However, when I inspect the logs (by using docker logs cvat_server) after a failed email attempt, I see the following error message:
[2024-02-04 18:08:10,859] ERROR django.request: Internal Server Error: /api/invitations/3SGAVXioLEGqTkPZBTyuWi4TkESbJlzTkSWnsSe1MhRDpEyTAzpOXHl4OHUrLnkh/resend
I have tried restarting the CVAT service and the Docker container, but the issue persists. I have also checked the cvat/settings/base.py file inside the container, and it appears that the EMAIL_BACKEND is set to None, which I believe is the default value and should be overridden by the environment variable.
I am using the Docker deployment method and have ensured that all dependencies are installed according to the official CVAT documentation. I have not made any custom modifications to the CVAT codebase.

Expected Behavior

Just send invitation email successfully.

Possible Solution

Tried modifing base.py/email_settings.py/docker-compose.yml (simply adding my email config to it/them), but nothing changed.

Context

No response

Environment

git log -1
commit b7cc5627daa04958ed045e4b3fe9fd68ec3c9e01 (HEAD -> develop, origin/develop, origin/HEAD)
Author: Boris Sekachev <boris.sekachev@yandex.ru>
Date:   Fri Feb 2 00:03:11 2024 +0200

lsb_release -a 
No LSB modules are available.
Distributor ID: Ubuntu
Description:    Ubuntu 20.04.6 LTS
Release:        20.04
Codename:       focal

docker version
Client: Docker Engine - Community
 Version:           25.0.2
 API version:       1.44
 Go version:        go1.21.6
 Git commit:        29cf629
 Built:             Thu Feb  1 00:23:19 2024
 OS/Arch:           linux/amd64
 Context:           default

Server: Docker Engine - Community
 Engine:
  Version:          25.0.2
  API version:      1.44 (minimum version 1.24)
  Go version:       go1.21.6
  Git commit:       fce6e0c
  Built:            Thu Feb  1 00:23:19 2024
  OS/Arch:          linux/amd64
  Experimental:     false
 containerd:
  Version:          1.6.28
  GitCommit:        ae07eda36dd25f8a1b98dfbf587313b99c0190bb
 runc:
  Version:          1.1.12
  GitCommit:        v1.1.12-0-g51d5e94
 docker-init:
  Version:          0.19.0
  GitCommit:        de40ad0
@Farenweh Farenweh added the bug Something isn't working label Feb 4, 2024
@bsekachev
Copy link
Member

Hello,

Why did you think, that it is configurable via docker compose?
Add your settings to django settings file (e.g. cvat/settings/production.py)

And you will need to rebuild docker images after that.

@bsekachev bsekachev added question Further information is requested and removed bug Something isn't working labels Feb 5, 2024
@Farenweh
Copy link
Author

Farenweh commented Feb 6, 2024

Thanks a TON buddy, I'm a GREEEEN hand about Docker so I guess something I have tried might be wrong cauz still not very proficient with its usage. Following your advice, I attempted to add the Email_Backend configuration to the cvat/settings/production.py, base.py, and email_settings.py files, like this (in production.py)

# Copyright (C) 2018-2022 Intel Corporation
#
# SPDX-License-Identifier: MIT

from .base import *

DEBUG = False

NUCLIO['HOST'] = os.getenv('CVAT_NUCLIO_HOST', 'nuclio')

# Django-sendfile:
# https://github.com/moggers87/django-sendfile2
SENDFILE_BACKEND = 'django_sendfile.backends.nginx'
SENDFILE_URL = '/'
EMAIL_HOST = 'smtp.qq.com'
EMAIL_PORT = '587'
EMAIL_USE_SSL = True
EMAIL_HOST_USER = 'xxxx@qq.com'
EMAIL_HOST_PASSWORD = 'xxxx'

and then rebuilt the containers. However, I encountered the same issue and have not been able to successfully configure the email backend.
In an effort to resolve this issue, I've tried all I can do but have not found a suitable solution. Therefore, I would like to humbly request your detailed guidance on how to correctly configure the email backend and rebuild my container. Your generous assistance would be greatly appreciated.
Once again, thank you SOOOO much for your patience and support!

@bsekachev
Copy link
Member

What command did you use to rebuild images?

@Farenweh
Copy link
Author

Farenweh commented Feb 7, 2024

I added my settings to home/django/cvat/settings/production.py in the running cvat_server container through VSCode, then docker commit -a "myself" -m "add email" bce6d0f40684, and restarted container by docker compose down and docker compose up -d.

@vlad-tkalenko
Copy link

I had exactly the same problem last days. It was fixed after editing your email settings into base.py and rebuilding cvat image with this command:
docker compose -f docker-compose.yml -f docker-compose.dev.yml build
Here link to the docs

@bsekachev
Copy link
Member

I hope the suggestion helped you.

@mohsin-ashraf
Copy link

docker compose -f docker-compose.yml -f docker-compose.dev.yml build

I am running into the same issue. After trying the above command you shared I get the following error.

Traceback (most recent call last):
cvat_worker_analytics_reports  |   File "/opt/venv/lib/python3.10/site-packages/django/db/backends/base/base.py", line 289, in ensure_connection
cvat_worker_analytics_reports  |     self.connect()
cvat_worker_analytics_reports  |   File "/opt/venv/lib/python3.10/site-packages/django/utils/asyncio.py", line 26, in inner
cvat_worker_analytics_reports  |     return func(*args, **kwargs)
cvat_worker_analytics_reports  |   File "/opt/venv/lib/python3.10/site-packages/django/db/backends/base/base.py", line 270, in connect
cvat_worker_analytics_reports  |     self.connection = self.get_new_connection(conn_params)
cvat_worker_analytics_reports  |   File "/opt/venv/lib/python3.10/site-packages/django/utils/asyncio.py", line 26, in inner
cvat_worker_analytics_reports  |     return func(*args, **kwargs)
cvat_worker_analytics_reports  |   File "/opt/venv/lib/python3.10/site-packages/django/db/backends/postgresql/base.py", line 275, in get_new_connection
cvat_worker_analytics_reports  |     connection = self.Database.connect(**conn_params)
cvat_worker_analytics_reports  |   File "/opt/venv/lib/python3.10/site-packages/psycopg2/__init__.py", line 122, in connect
cvat_worker_analytics_reports  |     conn = _connect(dsn, connection_factory=connection_factory, **kwasync)
cvat_worker_analytics_reports  | psycopg2.OperationalError: connection to server at "127.0.0.1", port 5432 failed: Connection refused
cvat_worker_analytics_reports  |        Is the server running on that host and accepting TCP/IP connections?
cvat_worker_analytics_reports  | 
cvat_worker_analytics_reports  | 
cvat_worker_analytics_reports  | The above exception was the direct cause of the following exception:
cvat_worker_analytics_reports  | 
cvat_worker_analytics_reports  | Traceback (most recent call last):
cvat_worker_analytics_reports  |   File "/home/django/manage.py", line 20, in <module>
cvat_worker_analytics_reports  |     execute_from_command_line(sys.argv)
cvat_worker_analytics_reports  |   File "/opt/venv/lib/python3.10/site-packages/django/core/management/__init__.py", line 442, in execute_from_command_line
cvat_worker_analytics_reports  |     utility.execute()
cvat_worker_analytics_reports  |   File "/opt/venv/lib/python3.10/site-packages/django/core/management/__init__.py", line 436, in execute
cvat_worker_analytics_reports  |     self.fetch_command(subcommand).run_from_argv(self.argv)
cvat_worker_analytics_reports  |   File "/opt/venv/lib/python3.10/site-packages/django/core/management/base.py", line 412, in run_from_argv
cvat_worker_analytics_reports  |     self.execute(*args, **cmd_options)
cvat_worker_analytics_reports  |   File "/opt/venv/lib/python3.10/site-packages/django/core/management/base.py", line 458, in execute
cvat_worker_analytics_reports  |     output = self.handle(*args, **options)
cvat_worker_analytics_reports  |   File "/opt/venv/lib/python3.10/site-packages/django/core/management/base.py", line 106, in wrapper
cvat_worker_analytics_reports  |     res = handle_func(*args, **kwargs)
cvat_worker_analytics_reports  |   File "/opt/venv/lib/python3.10/site-packages/django/core/management/commands/migrate.py", line 117, in handle
cvat_worker_analytics_reports  |     executor = MigrationExecutor(connection, self.migration_progress_callback)
cvat_worker_analytics_reports  |   File "/opt/venv/lib/python3.10/site-packages/django/db/migrations/executor.py", line 18, in __init__
cvat_worker_analytics_reports  |     self.loader = MigrationLoader(self.connection)
cvat_worker_analytics_reports  |   File "/opt/venv/lib/python3.10/site-packages/django/db/migrations/loader.py", line 58, in __init__
cvat_worker_analytics_reports  |     self.build_graph()
cvat_worker_analytics_reports  |   File "/opt/venv/lib/python3.10/site-packages/django/db/migrations/loader.py", line 235, in build_graph
cvat_worker_analytics_reports  |     self.applied_migrations = recorder.applied_migrations()
cvat_worker_analytics_reports  |   File "/opt/venv/lib/python3.10/site-packages/django/db/migrations/recorder.py", line 81, in applied_migrations
cvat_worker_analytics_reports  |     if self.has_table():
cvat_worker_analytics_reports  |   File "/opt/venv/lib/python3.10/site-packages/django/db/migrations/recorder.py", line 57, in has_table
cvat_worker_analytics_reports  |     with self.connection.cursor() as cursor:
cvat_worker_analytics_reports  |   File "/opt/venv/lib/python3.10/site-packages/django/utils/asyncio.py", line 26, in inner
cvat_worker_analytics_reports  |     return func(*args, **kwargs)
cvat_worker_analytics_reports  |   File "/opt/venv/lib/python3.10/site-packages/django/db/backends/base/base.py", line 330, in cursor
cvat_worker_analytics_reports  |     return self._cursor()
cvat_worker_analytics_reports  |   File "/opt/venv/lib/python3.10/site-packages/django/db/backends/base/base.py", line 306, in _cursor
cvat_worker_analytics_reports  |     self.ensure_connection()
cvat_worker_analytics_reports  |   File "/opt/venv/lib/python3.10/site-packages/django/utils/asyncio.py", line 26, in inner
cvat_worker_analytics_reports  |     return func(*args, **kwargs)
cvat_worker_analytics_reports  |   File "/opt/venv/lib/python3.10/site-packages/django/db/backends/base/base.py", line 288, in ensure_connection
cvat_worker_analytics_reports  |     with self.wrap_database_errors:
cvat_worker_analytics_reports  |   File "/opt/venv/lib/python3.10/site-packages/django/db/utils.py", line 91, in __exit__
cvat_worker_analytics_reports  |     raise dj_exc_value.with_traceback(traceback) from exc_value
cvat_worker_analytics_reports  |   File "/opt/venv/lib/python3.10/site-packages/django/db/backends/base/base.py", line 289, in ensure_connection
cvat_worker_analytics_reports  |     self.connect()
cvat_worker_analytics_reports  |   File "/opt/venv/lib/python3.10/site-packages/django/utils/asyncio.py", line 26, in inner
cvat_worker_analytics_reports  |     return func(*args, **kwargs)
cvat_worker_analytics_reports  |   File "/opt/venv/lib/python3.10/site-packages/django/db/backends/base/base.py", line 270, in connect
cvat_worker_analytics_reports  |     self.connection = self.get_new_connection(conn_params)
cvat_worker_analytics_reports  |   File "/opt/venv/lib/python3.10/site-packages/django/utils/asyncio.py", line 26, in inner
cvat_worker_analytics_reports  |     return func(*args, **kwargs)
cvat_worker_analytics_reports  |   File "/opt/venv/lib/python3.10/site-packages/django/db/backends/postgresql/base.py", line 275, in get_new_connection
cvat_worker_analytics_reports  |     connection = self.Database.connect(**conn_params)
cvat_worker_analytics_reports  |   File "/opt/venv/lib/python3.10/site-packages/psycopg2/__init__.py", line 122, in connect
cvat_worker_analytics_reports  |     conn = _connect(dsn, connection_factory=connection_factory, **kwasync)
cvat_worker_analytics_reports  | django.db.utils.OperationalError: connection to server at "127.0.0.1", port 5432 failed: Connection refused
cvat_worker_analytics_reports  |        Is the server running on that host and accepting TCP/IP connections?

Before running this command I am able to connect to the database properly without any problem, but as soon as I update it with the above command and restart the docker I start seeing this error.

@YaoJusheng
Copy link

Is the issue fixed?

I configured email configuration in file base.py and changed EMAIL_BACKEND to 'django.core.mail.backends.smtp.EmailBackend' in file email_settings.py.

After inviting a user, got the error hint of "xxx. Email backend is not configured.", but it was solved when I moved configuration item EMAIL_BACKEND into file base.py.

It's not clear what the email_settings file means in this case, because email-related configurations don't take effect here.

@GaberHassan
Copy link

Hello,
I am facing the same issue .
What if i want to invite 2 users as worker such as xx1@gmail.com
Xx2@gmail.com

What will be the clear steps to do that ?

@mohsin-ashraf
Copy link

Hello,
I am facing the same issue .
What if i want to invite 2 users as worker such as xx1@gmail.com
Xx2@gmail.com

What will be the clear steps to do that ?

First let those users to register/sign up on the CVAT

Once the do that you (owner of CVAT) can add them in the organization by typing their email address and inviting them

@GaberHassan
Copy link

Thanks for answering

Yes i did that but i am facing this error
"xxx. Email backend is not configured."
How to solve it ?

Hello,
I am facing the same issue .
What if i want to invite 2 users as worker such as xx1@gmail.com
Xx2@gmail.com
What will be the clear steps to do that ?

First let those users to register/sign up on the CVAT

Once the do that you (owner of CVAT) can add them in the organization by typing their email address and inviting them

@nisar2
Copy link

nisar2 commented Jun 24, 2024

bump. could someone please explain exactly how to set up the email backend? i've tried all the suggestions mentioned here to no avail. also, does this work with gmail?

@eric612
Copy link

eric612 commented Jul 16, 2024

There had an example in cvat\tests\docker-compose.email.yml , copy these lines into your yml , and config cvat\settings\email_settings.py

@idako2023
Copy link

Fixed this issue by configured email_settings.py like :

Email backend settings for Django

EMAIL_BACKEND = 'django.core.mail.backends.console.EmailBackend'
EMAIL_HOST = 'example.com'
EMAIL_PORT = 587
EMAIL_HOST_USER = 'your_account@example.com'
EMAIL_HOST_PASSWORD = 'your_encryped_code'
EMAIL_USE_TLS = True

then use this command restart docker:
docker compose -f docker-compose.yml -f tests/docker-compose.email.yml up -d

you can send your mail successfully, while don't forget finish some server side settings such as let the port pass through ...

@ainnotate
Copy link

cvat/settings/production.py

@idako2023, after this change I don't see the error anymore. I get a notification message "Invitation was sent successfully". However, emails are not getting delivered.

Do we need to re-build the relevant docker images?

How do I see the relevant logs in this case?

Thanks in advance.

@santo4ul
Copy link

santo4ul commented Aug 6, 2024

I tried all settings from this ticket. Howver, from the logs, I still see the default values such as example.com webmaster@localhost being used. Am I missing something here?

2024-08-06 15:07:10,025 DEBG 'uvicorn-1' stdout output:
Content-Type: text/html; charset="utf-8"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Subject: [example.com] You're invited to join haidata1 organization in CVAT!
From: webmaster@localhost
To: myemail@gmail.com
Date: Tue, 06 Aug 2024 15:07:10 -0000
Message-ID: <172295683002.53.5947727498718777060@eb2c6fad4e66>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests