Failing to connect to SMTP mail server

Hi everybody,

I’m having trouble configuring my mail server on Discourse.

I’m running my own SMTP server with OpenSMTPD. It works, I’m using it successfully with my Gitea and my Nextcloud.

Discourse doesn’t seem to like it though. When I try to register my admin account I don’t receive the confirmation mail.

The log in shared/standalone/log/rails/production.log says for each mail:

Sent mail to [my mail address] (64.9ms)
Job exception: Cannot assign requested address - connect(2) for "[my mail server]" port 587

My mail server never gets any connections according to its logs.

These are the mail settings from my app.yml:

DISCOURSE_SMTP_ADDRESS: [my mail server]
DISCOURSE_SMTP_PORT: 587
DISCOURSE_SMTP_USER_NAME: [my mail server user]
DISCOURSE_SMTP_PASSWORD: "[my password]"
#DISCOURSE_SMTP_ENABLE_START_TLS: true           # (optional, default true)

Again, the exact same settings (same user, same address, same password, same port, also STARTTLS) are working in my Gitea and my Nextcloud without problems.

I already tried:

  • Putting the password in single quotes instead of double quotes
  • Setting TLS to false
  • Setting a custom from-mail at the end of app.yml (though this probably isn’t the problem as my NC/Gitea use noreply@subdomain.domain.tld as addresses just like Discourse does and it works)
  • Searching for the error message in the Discourse log, but I didn’t find anything.
  • For the record, I ran launcher rebuild app after each change.
  • telnet [my mail server] connects just fine.

I’m running Discourse on my home server, the SMTP server is on my VPS (both run Arch Linux).

Anybody have any ideas what could be going wrong?

It looks like discourse can’t connect to your mail server.

Can you telnet my-mail-server 587 from the server? From inside the container?

You can see if ./discourse-doctor gives you any clues.

4 Likes

Telnetting from inside the container and discourse-doctor both failed with the exact same message.

It brought me onto the right track though. I tried out telnet from some other machines and stumbled upon the problem with one with IPv6 disabled: My mail server didn’t accept IPv4 connections.
Nextcloud and Gitea on the same machine were fine using IPv6, but Discourse seemingly doesn’t (maybe a Docker limitation?).

Anyway: I fixed the mail server config and it works flawlessly now. Thanks for the help! :smile:

4 Likes