Environement variables not considered - BASIC AUTH and N8N_SMTP

I configured my docker launch like this :

docker run -it --rm --name n8n -p 5678:5678 -v ~/.n8n:/home/node/.n8n -e N8N_BASIC_AUTH_ACTIVE="true" -e N8N_BASIC_AUTH_USER="myuser" -e N8N_BASIC_AUTH_PASSWORD="mypassword" -e N8N_EMAIL_MODE="smtp" -e N8N_SMTP_HOST="smtp.gmail.com" -e N8N_SMTP_USER="[email protected]" -e N8N_SMTP_PASS="mypassword" -e N8N_SMTP_SENDER="[email protected]" n8nio/n8n

What is the error message (if any)?

For the basic auth, no username/password is asked.

For the smtp, n8n looks like detecting something is it don’t ask me to configure smtp, but invitaiton mail for new users are not sent :

Created user shell(s) successfully
ERROR RESPONSE
ResponseError: There is a problem with your SMTP setup! Connection timeout
    at /usr/local/lib/node_modules/n8n/dist/src/UserManagement/routes/users.js:28:23
    at processTicksAndRejections (node:internal/process/task_queues:96:5)
    at async /usr/local/lib/node_modules/n8n/dist/src/ResponseHelper.js:91:26 {
  httpStatusCode: 500
}
Failed to send email

Hey @AlexyTG, I am sorry to hear you’re running into trouble here. I just tried the docker run command you have shared and am asked for my password as expected.

Is there a chance you have simply stored your password in your browser or password manager so the auth screen doesn’t pop up? What does curl -v http://localhost:5678/ return for you?

Thanks for the answer, indeed, the user/password was saved.

But still issue with the SMTP configuration.

Just try to use docker file and docker-compose but still the same error.

Info : n8n is hosted on my VPS

I have very similliar problem with User Management.
I got the error during invite new user:

ResponseError: Failed to send email to [email protected]
    at /usr/local/lib/node_modules/n8n/dist/src/UserManagement/routes/users.js:320:19
    at processTicksAndRejections (node:internal/process/task_queues:96:5)
    at async /usr/local/lib/node_modules/n8n/dist/src/ResponseHelper.js:91:26 {
  httpStatusCode: 500
}

My docker-compose:

services:

  postgres:
    image: postgres:11
    restart: always
    environment:
      - POSTGRES_USER
      - POSTGRES_PASSWORD
      - POSTGRES_DB
      - POSTGRES_NON_ROOT_USER
      - POSTGRES_NON_ROOT_PASSWORD
    volumes:
      - ./init-data.sh:/docker-entrypoint-initdb.d/init-data.sh
      - ./n8n_db:/var/lib/postgresql/data
  n8n:
    image: n8nio/n8n:latest-debian
    restart: always
    environment:
      - DB_TYPE=postgresdb
      - DB_POSTGRESDB_HOST=postgres
      - DB_POSTGRESDB_PORT=5432
      - DB_POSTGRESDB_DATABASE=${POSTGRES_DB}
      - DB_POSTGRESDB_USER=${POSTGRES_NON_ROOT_USER}
      - DB_POSTGRESDB_PASSWORD=${POSTGRES_NON_ROOT_PASSWORD}
      - N8N_BASIC_AUTH_ACTIVE=false
      - N8N_BASIC_AUTH_USER
      - N8N_BASIC_AUTH_PASSWORD
      - N8N_EMAIL_MODE
      - N8N_SMTP_HOST
      - N8N_SMTP_PORT
      - N8N_SMTP_USER
      - N8N_SMTP_PASS
      - N8N_SMTP_SENDER
      - N8N_SMTP_SSL
      - N8N_PROTOCOL
    ports:
      - 5678:5678
    links:
      - postgres
    volumes:
      - ./.n8n:/home/node/.n8n
    # Wait 5 seconds to start n8n to make sure that PostgreSQL is ready
    # when n8n tries to connect to it
    command: /bin/sh -c "sleep 5; n8n start"

My SMTP env:

# SMTP configuration
N8N_EMAIL_MODE='smtp'
N8N_SMTP_HOST='smtp_host'
N8N_SMTP_PORT=25
N8N_SMTP_USER='n8n'
N8N_SMTP_PASS='pass'
N8N_SMTP_SENDER='n8n'
N8N_SMTP_SSL='false'

N8N_PROTOCOL='https'

Hi @piotrtrojanowski-dev, this sounds like a problem with your SMTP host. Which email provider are you using?

On a separate note, enabling user management would disable basic auth, so you can remove the N8N_BASIC_AUTH variables.

@MutedJam My postfix main.cf:

# See /usr/share/postfix/main.cf.dist for a commented, more complete version


# Debian specific:  Specifying a file name will cause the first
# line of that file to be used as the name.  The Debian default
# is /etc/mailname.
#myorigin = /etc/mailname

smtpd_banner = $myhostname ESMTP $mail_name (Debian/GNU)
biff = no

# appending .domain is the MUA's job.
append_dot_mydomain = no

# Uncomment the next line to generate "delayed mail" warnings
#delay_warning_time = 4h

readme_directory = no

# See http://www.postfix.org/COMPATIBILITY_README.html -- default to 2 on
# fresh installs.
compatibility_level = 2

# TLS parameters
smtpd_tls_cert_file=/etc/ssl/certs/ssl-cert-snakeoil.pem
smtpd_tls_key_file=/etc/ssl/private/ssl-cert-snakeoil.key
smtpd_use_tls=no
smtpd_tls_session_cache_database = btree:${data_directory}/smtpd_scache
smtp_tls_session_cache_database = btree:${data_directory}/smtp_scache
smtpd_sasl_auth_enable = yes
# See /usr/share/doc/postfix/TLS_README.gz in the postfix-doc package for
# information on enabling SSL in the smtp client.

smtpd_relay_restrictions = permit_mynetworks permit_sasl_authenticated defer_unauth_destination
myhostname = my_host
alias_maps = hash:/etc/aliases
alias_database = hash:/etc/aliases
mydestination = $myhostname, localhost.localdomain, , localhost
relayhost =
mynetworks = 127.0.0.0/8 [::ffff:127.0.0.0]/104 [::1]/128 0.0.0.0/0
mailbox_size_limit = 0
recipient_delimiter = +
inet_interfaces = all
inet_protocols = all

@MutedJam I got error: warning: SASL authentication failure: Password verification faile
What is actually N8N_SMTP_PASS and Ń8N_SMTP_USER ? I should have special user on my host?

Hey @piotrtrojanowski-dev,

The User and Pass credentials should match a user in your Postfix SASL config.

@jon Ok, thanks a lot! My credentails was wrong.

1 Like

On my side, my SMTP credentials are the same as those defined in my web app (that can send mail)

Hey @AlexyTG,

Your error shows a connection timeout so I suspect it could be network issue and the container is having a hard time connecting to the google smtp server.

Assuming you have smtp enabled and less secure app access granted.