Search code examples
redash

Redash: Unable to send invitation/passowrd reset mails


After setting the email env variables as per https://redash.io/help/open-source/setup (for AWS SES)

sudo docker-compose run --rm server manage send_test_mail

works, and I receive the email as well.

But invitation emails do not get sent.

On trying this command - to send the invite directly,

sudo docker-compose run --rm server manage users invite [email protected] X [email protected]

I get the following error:

raise RuntimeError('Application was not able to create a URL '

RuntimeError: Application was not able to create a URL adapter for request independent URL generation. You might be able to fix this by setting the SERVER_NAME config variable.


Solution

  • From https://github.com/getredash/redash/issues/5266#issuecomment-847756246. Thanks to @kijimaD.


    I was in the same situation. I found a way to send an invitation email.

    After running docker-compose up, check the log when the browser invitation email is sent (↓excerpt).

    $ docker-compose up
    ...
    nginx_1             | 172.31.42.153 - - [24/May/2021:10:59:25 +0000] "POST /api/users/124/reset_password HTTP/1.1" 200 122 "https://example.com/users/124" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4430.212 Safari/537.36" "110.66.19.160"
    scheduler_1         | [2021-05-24 10:59:25,960][PID:16][ERROR][ForkPoolWorker-3] task_name=redash.tasks.send_mail task_id=39f69b3c-a109-43d5-bd31-c7dd99955427 Failed sending message: Reset your password
    scheduler_1         | Traceback (most recent call last):
    scheduler_1         |   File "/app/redash/tasks/general.py", line 58, in send_mail
    scheduler_1         |     mail.send(message)
    scheduler_1         |   File "/usr/local/lib/python2.7/site-packages/flask_mail.py", line 491, in send
    scheduler_1         |     with self.connect() as connection:
    scheduler_1         |   File "/usr/local/lib/python2.7/site-packages/flask_mail.py", line 144, in __enter__
    scheduler_1         |     self.host = self.configure_host()
    scheduler_1         |   File "/usr/local/lib/python2.7/site-packages/flask_mail.py", line 158, in configure_host
    scheduler_1         |     host = smtplib.SMTP(self.mail.server, self.mail.port)
    scheduler_1         |   File "/usr/local/lib/python2.7/smtplib.py", line 256, in __init__
    scheduler_1         |     (code, msg) = self.connect(host, port)
    scheduler_1         |   File "/usr/local/lib/python2.7/smtplib.py", line 317, in connect
    scheduler_1         |     self.sock = self._get_socket(host, port, self.timeout)
    scheduler_1         |   File "/usr/local/lib/python2.7/smtplib.py", line 292, in _get_socket
    scheduler_1         |     return socket.create_connection((host, port), timeout)
    scheduler_1         |   File "/usr/local/lib/python2.7/socket.py", line 575, in create_connection
    scheduler_1         |     raise err
    scheduler_1         | error: [Errno 99] Cannot assign requested address
    scheduler_1         | [2021-05-24 10:59:25,961][PID:16][INFO][ForkPoolWorker-3] Task redash.tasks.send_mail[39f69b3c-a109-43d5-bd31-c7dd99955427] succeeded in 0.00195795716718s: None
    server_1            | [2021-05-24 10:59:28,257][PID:12][INFO][metrics] method=GET path=/health_check endpoint=redash_index status=302 content_type=text/html; charset=utf-8 content_length=311 duration=1.80 query_count=0 query_duration=0.00
    

    Obviously, the error content is different from the test command one. This looks like an error that the scheduler_1 instance is not able to read the port, host.

    In other words, the instance don't read environment variables. I added an environment variable to worker in docker-compose.yml based on this error.

    After run docker-compose down && docker-compose up -d, I was able to successfully send the invitation email in my browser.+1 However, the test command docker-compose run --rm server manage users invite [email protected] test-user [email protected] does not change the error message.

    I have a question about the reliability of the test command in specific situations. Obviously, the behavior of the test command is different from that of the actual browser. This seems to have confused many people...

    My advice to anyone facing the same problem is to operate the browser and see the actual error in the log instead of checking it with a test command.

    I hope this will help others who are struggling with the same situation.

    The following is my docker-compose and env configuration.

    docker-compose

    $ cat docker-compose.yml
    version: "2"
    x-redash-service: &redash-service
      image: redash/redash:8.0.0.b32245
      depends_on:
        - postgres
        - redis
      env_file: /opt/redash/env
      restart: always
    services:
      server:
        <<: *redash-service
        command: server
        ports:
          - "5000:5000"
        environment:
          REDASH_WEB_WORKERS: 4
        env_file: /opt/redash/env
      scheduler:
        <<: *redash-service
        command: scheduler
        environment:
          QUEUES: "celery"
          WORKERS_COUNT: 1
          REDASH_WEB_WORKERS: 4
        env_file: /opt/redash/env # <------------- Add
      scheduled_worker:
        <<: *redash-service
        command: worker
        environment:
          QUEUES: "scheduled_queries,schemas"
          WORKERS_COUNT: 1
          REDASH_WEB_WORKERS: 4
        env_file: /opt/redash/env # <------------- Add
      adhoc_worker:
        <<: *redash-service
        command: worker
        environment:
          QUEUES: "queries"
          WORKERS_COUNT: 2
          REDASH_WEB_WORKERS: 4
        env_file: /opt/redash/env # <------------- Add
      redis:
        image: redis:5.0-alpine
        restart: always
      postgres:
        image: postgres:9.6-alpine
        env_file: /opt/redash/env
        volumes:
          - /opt/redash/postgres-data:/var/lib/postgresql/data
        restart: always
      nginx:
        image: redash/nginx:latest
        ports:
          - "80:80"
        depends_on:
          - server
        links:
          - server:redash
        restart: always
    env
    $ cat env
    PYTHONUNBUFFERED=0
    REDASH_LOG_LEVEL=INFO
    REDASH_REDIS_URL=redis://redis:6379/0
    POSTGRES_PASSWORD=...
    REDASH_COOKIE_SECRET=...
    REDASH_SECRET_KEY=...
    REDASH_DATABASE_URL=...
    
    # Mail
    REDASH_MAIL_SERVER=...
    REDASH_MAIL_PORT=...
    REDASH_MAIL_USE_TLS=...
    REDASH_MAIL_USERNAME=...
    REDASH_MAIL_PASSWORD=...
    [email protected]
    REDASH_HOST=https://example.com
    REDASH_SERVER_NAME=https://example.com