yochaigal / kettlewright

Kettlewright
https://kettlewright.com
GNU General Public License v3.0
44 stars 7 forks source link

Error with registration mail #127

Closed aberral closed 1 month ago

aberral commented 1 month ago

Hi, I've been trying to run Kettlewright on my server as a Docker container. The container is running, the website is accessible, but when I try to register an account the container throws this exception (as seen in the logs):

NFO:root:Not using Redis; falling back to local eventlet sessions. Consolidation complete. Data written to app/static/json/backgrounds/background_data.json Consolidation complete. Data written to app/static/json/party_events/event_data.json base_url: http://localhost:8008 INFO [alembic.runtime.migration] Context impl SQLiteImpl. INFO [alembic.runtime.migration] Will assume non-transactional DDL. INFO [alembic.runtime.migration] Running upgrade -> abbbce54689f, init db [2024-09-25 08:55:44 +0000] [1] [INFO] Starting gunicorn 23.0.0 [2024-09-25 08:55:44 +0000] [1] [INFO] Listening at: http://0.0.0.0:8000 (1) [2024-09-25 08:55:44 +0000] [1] [INFO] Using worker: eventlet [2024-09-25 08:55:44 +0000] [8] [INFO] Booting worker with pid: 8 INFO:root:Not using Redis; falling back to local eventlet sessions. Removed existing file: app/static/json/backgrounds/background_data.json Consolidation complete. Data written to app/static/json/backgrounds/background_data.json Removed existing file: app/static/json/party_events/event_data.json Consolidation complete. Data written to app/static/json/party_events/event_data.json base_url: http://localhost:8008 Exception in thread Thread-1 (send_async_email): Traceback (most recent call last): File "/usr/local/lib/python3.10/threading.py", line 1016, in _bootstrap_inner self.run() File "/usr/local/lib/python3.10/threading.py", line 953, in run self._target(*self._args, **self._kwargs) File "/app/app/email.py", line 10, in send_async_email mail.send(msg) File "/usr/local/lib/python3.10/site-packages/flask_mail/init.py", line 539, in send with self.connect() as connection: File "/usr/local/lib/python3.10/site-packages/flask_mail/init.py", line 127, in enter self.host = self.configure_host() File "/usr/local/lib/python3.10/site-packages/flask_mail/init.py", line 144, in configure_host host = smtplib.SMTP(self.mail.server, self.mail.port) File "/usr/local/lib/python3.10/smtplib.py", line 255, in init (code, msg) = self.connect(host, port) File "/usr/local/lib/python3.10/smtplib.py", line 341, in connect self.sock = self._get_socket(host, port, self.timeout) File "/usr/local/lib/python3.10/smtplib.py", line 312, in _get_socket return socket.create_connection((host, port), timeout, File "/usr/local/lib/python3.10/site-packages/eventlet/green/socket.py", line 44, in create_connection for res in getaddrinfo(host, port, 0, SOCK_STREAM): File "/usr/local/lib/python3.10/site-packages/eventlet/support/greendns.py", line 578, in getaddrinfo raise socket.gaierror(socket.EAI_NONAME, 'No address found') socket.gaierror: [Errno -2] No address found

I've tried to pinpoint where the error is coming from, but have been unable to do so. The .env configuration that I have is something like this:

BASE_URL=http://127.0.0.1:8008
SECRET_KEY=***********
SQLALCHEMY_DATABASE_URI=sqlite:///db.sqlite

# Gmail config
MAIL_SERVER=smtp.gmail.com  
MAIL_PORT=587              
MAIL_USE_TLS=1              
MAIL_USERNAME=****@gmail.com  
MAIL_PASSWORD=*********

# Optional
REQUIRE_SIGNUP_CODE=False   
# SIGNUP_CODE=[your_signup_code]  

# Redis
USE_REDIS=False              
# REDIS_URL=redis://redis-server:6379/0  

I've tried to exec into the container and pinging 'smtp.google', which is successful. I've also run the following Python script to test that the credentials that I have for gmail are working as intended:

from flask import Flask
from flask_mail import Mail, Message

app = Flask(__name__)

# Mail config
app.config['MAIL_SERVER'] = 'smtp.gmail.com'
app.config['MAIL_PORT'] = 587
app.config['MAIL_USE_TLS'] = 1
app.config['MAIL_USERNAME'] = 'sender@gmail.com'
app.config['MAIL_PASSWORD'] = '****' 
app.config['MAIL_DEFAULT_SENDER'] = 'sender@gmail.com'

mail = Mail(app)

with app.app_context():
    msg = Message("Test mail",
                  recipients=["recipient@gmail.com"])
    msg.body = "Test mail sent from Docker"
    try:
        mail.send(msg)
        print("Success!")
    except Exception as e:
        print(f"error")

This test email works and is received (both sent and received by gmail accounts). So I am at a bit of a loss as to how to try to fix this problem. I have also ruled out a port or system related error as I have tested it on another machine with and without other containers occupying port 8000. I hope you can help me solve this problem and congratulations on the app, it is fantastic.

yochaigal commented 1 month ago

What operating system are you using?

aberral commented 1 month ago

Hi there!, I have tested it in unix like OS (Ubuntu 22.04.4 LTS and CasaOS, which is Debian GNU/Linux 11 (bullseye)).

yochaigal commented 1 month ago

I just pulled the docker image on a clean system (ubuntu 24.04). I was able to register a brand-new email with no issue. To go over my steps:

  1. Delete all local docker images and volumes (just to be sure): docker system prune --volumes --all --force

  2. Created the .env:

BASE_URL=http://127.0.0.1:8000 SECRET_KEY=randomkey SQLALCHEMY_DATABASE_URI=sqlite:///db.sqlite MAIL_SERVER=smtp.mailgun.org MAIL_PORT=587 MAIL_USE_TLS=1 MAIL_USERNAME=no-reply@kettlewright.com MAIL_PASSWORD=somepassword REQUIRE_SIGNUP_CODE=True SIGNUP_CODE=somecode WORKERS=1 USE_REDIS=False REDIS_URL=redis://redis-server:6379/0%

  1. Pull the image: docker pull yochaigal/kettlewright

  2. Run the container: docker run -d --name kettlewright --env-file ~/docker/kettlewright/.env -v kettlewright_db:/app/instance -p 8000:8000 --restart always yochaigal/kettlewright

  3. Go to 127.0.0.1:8000

  4. Sign up.

  5. Received email.

Can you try to recreate the env file? Copy and paste what I have and fill it in.

yochaigal commented 1 month ago

Did you run the python script inside the container? I know you said you pinged the server from within it, I just wonder if there is a larger DNS issue going on with the docker container's network itself. When you tested it on another machine, did the emails not send there as well? Could it be a local network issue?

I assume you're using an app password for google as well?

yochaigal commented 1 month ago

Just to be sure, I setup an app password in Gmail (using a google workspace account) and changed my .env accordingly. I had no issues.

aberral commented 1 month ago

I've re-run and re-deployed the image after pruning images & volumes as you said. It now works with the required sing-up code. Regarding your questions, yes, I've tested it on two separate networks, one at home and one at work. And yes, I'm indeed using a Google Apps password. I have tested removing the signup code and it seems to work as well. I suspect it was some weird error related to volumes or the image that disappeared after I pruned it.

yochaigal commented 1 month ago

Interesting! Did you rebuild the .env? There could have been whitespace or something. Anyway, glad it works now.

aberral commented 1 month ago

Yes, I used terminal to create a new .env in a different folder and pasted in and edited what you commented. The only difference I can see between the files is the randomkey used: "randomkey" in the working version and "a~UB;_uM^Kd$}?z)kfQ5<6" that i generated randomly. Maybe some character of this last randomkey was affecting the code in some way?. Anyways, thank you so much for your help, now I can share and enjoy it with my players!!! :)

yochaigal commented 1 month ago

Hmm, I don't think so. That key specifically relates to session data. Still, good to know!