Taiga docker: Email only works with CONSOLE backend

Hello, community.

I can see the emails Taiga CE sends in the taiga-back container’s log but when I set the EMAIL_BACKEND from console to smtp it seems emails dont reach my company internal email server.

I do know the company local SMTP server is working because other apps and scripts of mine use it and I have issued the following from inside taiga-back container:

$ curl --url 'smtp://smtp.mailserver.mycompany.domain.com:25' --mail-from 'sender@mycompany.domain.com' --mail-rcpt 'myself@mycompany.domain.com' --upload-file sample.file --insecure

Here’s taiga-docer/.env file:

[.....]
# Taiga's SMTP settings - Variables to send Taiga's emails to the users
EMAIL_BACKEND=smtp  # use an SMTP server or display the emails in the console (either "smtp" or "console")
EMAIL_HOST=smtp.mailserver.mycompany.domain.com  # SMTP server address
EMAIL_PORT=25   # default SMTP port
EMAIL_HOST_USER=  # user to connect the SMTP server
EMAIL_HOST_PASSWORD=  # SMTP user's password
EMAIL_DEFAULT_FROM=myself@mycompany.domain.com  # default email address for the automated emails
EMAIL_USE_TLS=False  # use TLS (secure) connection with the SMTP server
EMAIL_USE_SSL=False  # use implicit TLS (secure) connection with the SMTP server
[.....]

And when I enter the container:

$ docker exec -it taiga-docker-taiga-back-1 bash
root@a2d1b2910182:/taiga-back#

The email section in the settings/config.py file states:

#########################################
## EMAIL
#########################################
# https://docs.djangoproject.com/en/3.1/topics/email/
EMAIL_BACKEND = os.getenv('EMAIL_BACKEND', 'django.core.mail.backends.console.EmailBackend')
CHANGE_NOTIFICATIONS_MIN_INTERVAL = 120  # seconds

DEFAULT_FROM_EMAIL = os.getenv('DEFAULT_FROM_EMAIL', 'system@taiga.io')
EMAIL_USE_TLS = os.getenv('EMAIL_USE_TLS', 'False') == 'True'
EMAIL_USE_SSL = os.getenv('EMAIL_USE_SSL', 'False') == 'True'
EMAIL_HOST = os.getenv('EMAIL_HOST', 'localhost')
EMAIL_PORT = os.getenv('EMAIL_PORT', 587)
EMAIL_HOST_USER = os.getenv('EMAIL_HOST_USER', 'user')
EMAIL_HOST_PASSWORD = os.getenv('EMAIL_HOST_PASSWORD', 'password')

Seems like the settings are not there.

Maybe I am looking at the wrong file or perhaps that’s the way it is and I must look in another container.

Hi there,

The settings are exposed to taiga-back as environment variables, so if you do echo $EMAIL_HOST or any of the other variables, then you can see if they are set or not. If they are not, then python will get the default value (the second argument there to os.getenv()

After you set those variables on the .env file, though, make sure to restart the docker containers.

Regards!

Great! :white_check_mark: The environment variables were set correctly:


$ docker exec -it taiga-docker-taiga-back-1 bash

root@a2d1b2910182:/taiga-back # env |grep EMAIL

EMAIL_HOST=smtp.mailserver.mycompany.domain.com
EMAIL_BACKEND=django.core.mail.backends.smtp.EmailBackend
EMAIL_PORT=25
DEFAULT_FROM_EMAIL= myself@mycompany.domain.com

Now, the second stage is how to force Taiga to send my user an email message without changing my password.

Is there a way to do that?

It should be possible. Outside the docker container there should be a taiga-manage.sh script. Django’s manage.py (which is what the script uses under the hood) has a command called sendtestemail. You should be able to call taiga-manage.sh sendtestemail your@email and check if you receive it.

Yes, it is possible to invoke the builtin mail sender…

$ ./taiga-manage.sh sendtestemail myself@mycompany.domain.com
+ exec docker compose -f docker-compose.yml -f docker-compose-inits.yml run --rm taiga-manage sendtestemail myself@mycompany.domain.com
[+] Creating 1/0
 ✔ Container taiga-docker-taiga-db-1  Running                                                                                                                                              0.0s
Content-Type: text/plain; charset="utf-8"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Subject: Test email from 121adf64ec04 on 2023-10-23 19:19:19.125237+00:00
From: system@taiga.io
To: myself@mycompany.domain.com
Date: Mon, 23 Oct 2023 19:19:19 -0000
Message-ID: <169808875912.1.3137052844105060992@121adf64ec04>

If you're reading this, it was successful.
-------------------------------------------------------------------------------

…but my company SMTP server is not allowing to send email when the FROM: is an address from outside the domain (system@taiga.io)

I tried by entering the taiga-back container and changing the

DEFAULT_FROM_EMAIL = os.getenv('DEFAULT_FROM_EMAIL', 'system@taiga.io')

line and the running again the sendtestemail line and the sender address kept the same. I think I should properly access taiga-manage image in order to alter it and don’t know how to do it.

Anyway, I should be able to alter the values of the taiga-back DEFAULT_FROM_EMAIL variable in order for the Django subsystem to work properly for my facility: using a valid_address@mycompay.domain.com as the sender address.

Hi there,

You can alter them changing the EMAIL_DEFAULT_FROM environment variable and then restarting the container.

Did you try that?

Regards!

The environment variable is already set in the .env file, so I take the value from there and…

$ pwd
/home/localuser/repos/taiga-docker
$ grep EMAIL_DEFAULT .env
#EMAIL_DEFAULT_FROM=changeme@example.com  # default email address for the automated emails
EMAIL_DEFAULT_FROM=valid.address@mycompany.domain.com  # default email address for the automated emails

… since the invokation of ./taiga-manage.sh uses docker-compose.yml as an argument for the container taiga-manage, I check the variable assignation:

$ grep EMAIL_DEFAULT docker-compose.yml
  DEFAULT_FROM_EMAIL: "${EMAIL_DEFAULT_FROM}"

… and export the shell environment variable outside the container:

$ export EMAIL_DEFAULT_FROM=valid.address@mycompany.domain.com

…then lauch the taiga-manage.sh script:

$ ./taiga-manage.sh sendtestemail myself@mycompany.domain.com
+ exec docker compose -f docker-compose.yml -f docker-compose-inits.yml run --rm taiga-manage sendtestemail myself@mycompany.domain.com
[+] Creating 1/0
 ✔ Container taiga-docker-taiga-db-1  Running                                                                                                   0.0s
Content-Type: text/plain; charset="utf-8"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Subject: Test email from 12902d90c9ef on 2023-10-26 13:23:52.753954+00:00
From: system@taiga.io
To: myself@mycompany.domain.com
Date: Thu, 26 Oct 2023 13:23:52 -0000
Message-ID: <169832663278.1.16863504282308229665@12902d90c9ef>

If you're reading this, it was successful.
-------------------------------------------------------------------------------
$

…but it still is using the same value for the email from address.

Please specify where should I change the EMAIL_DEFAULT_FROM environment variable.

Hi there,

EMAIL_DEFAULT_FROM should only be set on the .env file.

Inside the container, it gets translated to DEFAULT_FROM_EMAIL, which is used by Taiga’s config.py.

You can check if it is set correctly by going inside a shell in taiga-back and executing echo DEFAULT_FROM_EMAIL.

If that variable is not set to the same value that you set as EMAIL_DEFAULT_FROM on the .env file, try doing docker-compose restart and try again.

Regards!

Hi, there.

Maybe something weird is happening or I am missing something in the way because the .env file hast the correct valid.address@mycompany.domain.com and if I go to a shell in the taiga-back container and check the content of the DEFAULT_FROM_EMAIL it is valid.address@mycompany.domain.com, too.

But executing the taiga-manager.sh script still uses system@taiga.io as the sender address and my company SMTP server policies doesn’t allow that.

So, the email is not accepted for delivery, I guess. I need to change the sender’s address.

Regards,