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

Invitation etc emails not being sent on the account of the code failing to generate urls #5266

Open
s7dhansh opened this issue Nov 12, 2020 · 7 comments

Comments

@s7dhansh
Copy link

I think this is a bug, but please correct me if I am overreaching. It may be a configuration issue but I have not found any doc to support the same.

On reading https://discuss.redash.io/t/email-invite-urls-not-generating/1044, it seems like a flask bug of not having the app context.

Issue Summary

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 x@x.com X admin@x.com

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.

Steps to Reproduce

  1. Set the email env variables as per https://redash.io/help/open-source/setup
  2. Try the test command - works
  3. Try the invite command - fails

Technical details:

  • Redash Version: Version: 8.0.0+b32245 (a16f551)
  • Browser/OS: AWS AMI
  • How did you install Redash: AWS AMI
@xuexiaoao
Copy link

I also encountered the same problem, is there a solution?

@kijimaD
Copy link

kijimaD commented May 25, 2021

@s7dhansh
@xuexiaoao

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

Conclusion of this comment: Add an environment variable for email configuration to worker in docker-compose.yml.

Encountered error

  • Click on the invitation email in the browser, but it is not sent.
  • Run test commands:
    • Success...send_test_mail docker-compose run --rm server manage send_test_mail my_email@example.com
    • Fail...send invite mail docker-compose run --rm server manage users invite user@example.com test-user admin@example.com

Run invite mail command↑ error: Flask error(excerpt)

File "/usr/local/lib/python2.7/site-packages/flask/helpers.py", line 299, in url_for
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.

Add SERVER_NAME to environment variable as the message instructed did not solve the problem.
In docker I was very confused by the unfamiliar flask error.

I relied on the error message of this command to investigate, but was unable to resolve this Flask error.

Solution: Add environment variables.

In the end, however, I was able to solve the problem from a different perspective.

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.👍
However, the test command docker-compose run --rm server manage users invite user@example.com test-user admin@example.com 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=...
REDASH_MAIL_DEFAULT_SENDER=info@example.com
REDASH_HOST=https://example.com
REDASH_SERVER_NAME=https://example.com

Technical details:

  • Redash Version: Version: 8.0.0+b32245 (a16f551)
  • Browser/OS: AWS AMI
  • How did you install Redash: getredash/setupscript

@s7dhansh
Copy link
Author

@kijimaD thank you so much. it works!

@cognitus
Copy link

@kijimaD it worked, Thanks!

@ravishankarachanta
Copy link

@kijimaD Thank you!! It worked!

@Gikls
Copy link

Gikls commented Jan 13, 2022

Hello. Faced the same issue with password reset. We running redash on our own gcp server, configuring via docker-compose. Using sendgrid as mails server. Test emails works fine, but not the password reset.

Here is docker compose
https://pastebin.com/VYfXpdHi
here is our env
https://pastebin.com/KCs4hVtD.
See only post request but no errors in logs.
Command:
docker-compose run --rm server manage users invite user@example.com test-user admin@example.com
Have the same error
Could you help please?
PS: Tried, solution above. Config files are before this change, but it's still not working

@jekeam
Copy link

jekeam commented Nov 7, 2023

Thank you very much. The docker-compose restart command does not work.
docker-compose down && docker-compose up -d - command worked for me.

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

No branches or pull requests

7 participants