self-hosted icon indicating copy to clipboard operation
self-hosted copied to clipboard

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

Open alexispurslane opened this issue 1 year ago • 7 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.

alexispurslane avatar Apr 22 '23 16:04 alexispurslane

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.

alexispurslane avatar Apr 22 '23 16:04 alexispurslane

I could move this to the backend repo

alexispurslane avatar Apr 22 '23 16:04 alexispurslane

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 [email protected]!
docker[204592]: revolt-api-1            | lettre error: Connection error: Cannot assign requested address (os error 99)

alexispurslane avatar Apr 22 '23 16:04 alexispurslane

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

alexispurslane avatar Apr 22 '23 16:04 alexispurslane

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

alexispurslane avatar Apr 22 '23 16:04 alexispurslane

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?

alexispurslane avatar Apr 22 '23 19:04 alexispurslane

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.

fungalcofe avatar Jun 15 '23 07:06 fungalcofe