revoltchat / self-hosted

Deploy Revolt using Docker.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

bug: Revolt docker container cannot talk to postfix smtp server at localhost:25

alexispurslane opened this issue · comments

What happened?

In order to allow Revolt to send emails, I set up a postfix server for outgoing emails on the same server the Revolt docker container is running on, listening on the standard port 25. There's no username and password, so no authentication to speak of, and I've opened that port on the firewall. I can connect to it and send emails from both my local computer and on the same server outside the docker container, and I've added the docker0 address to the list of networks the postfix accepts, so it should work, but when I try to turn emails on, I just get this:

thread 'main' panicked at 'Running in production without email is not recommended, set REVOLT_UNSAFE_NO_EMAIL=1 to override.', crates/quark/src/util/variables/delta.rs:79:13

over and over.

I went and checked the code, and the problem seems to be due to the fact that quark panics if all of the SMTP variables are not set and the UNSAFE_NO_EMAIL flag is not set, even if some of those SMTP variables (the password, in this case) aren't relevant.

I could move this to the backend repo

If I set the password to an empty string, it doesn't crash, and can attempt to send emails, but it doesn't appear to succeed in sending them:

docker[204592]: revolt-api-1            |  ERROR rauth::config::email_verification                       > Failed to send email to alexispurslane@pm.me!
docker[204592]: revolt-api-1            | lettre error: Connection error: Cannot assign requested address (os error 99)

Apparently, this is due to a service running in a docker container not being able to recognize localhost. Switching SMTP_HOST to host.docker.internal or my server's IP address (behind the router) changes the error to:

failed to lookup address information: Name or service not known

I don't know how to resolve this error, but it doesn't seem to step from Revolt.

Okay, so I resolved all the explicit errors, so Revolt SAYS that it was successful in sending the email, but nothing ever happens. What assumptions does it make about the setup of the SMTP server that might be causing this?

commented

Apparently, this is due to a service running in a docker container not being able to recognize localhost. Switching SMTP_HOST to host.docker.internal or my server's IP address (behind the router) changes the error to:

host.docker.internal is only for Docker Desktop (macOS and Windows).
There’s no easy nor fancy way to join host, but using its main IP.
What you could do is running that Postfix in a container too and having a network for both backend and Postfix.

@alexispurslane I spent a few days troubleshooting this very recently, if you didn't get your setup working you may be interested.

Docker usually assigns the IP 172.17.0.1 to its host network. You can check this for yourself by telnetting from the container (using docker exec -it /bin/bash) to the host. You can use this as the hostname, assuming that postfix and dovecot run on the same machine.

Note: You'll need to also see the revised approach to configuring Revolt, as well as implementing the extra parameters that I noted here: #89

Since this issue seems unrelated to Revolt, I'm going to close it out.
I did find https://stackoverflow.com/a/48547074, probably relevant.