Connecting to a SMTP server on localhost:25 without auth?

What are the correct settings passed to ./discourse-setup for connecting to an smtp server on localhost:25 without auth?

I’m very surprised that this isn’t supported OOTB; it’s the default config on most linux installs…

My server runs postfix locally; it is not accessible from the Internet. It works fine, for example, when running the mail command. I found a few unofficial guides on the Internet suggesting changes to /var/discourse/containers/app.yml, and I finally got it to install & start with the following settings:

  DISCOURSE_SMTP_ADDRESS: localhost
  DISCOURSE_SMTP_PORT: 25
  DISCOURSE_SMTP_USER_NAME: discourse@opensouceecology.org
  DISCOURSE_SMTP_PASSWORD: "none"
  DISCOURSE_SMTP_AUTHENTICATION: none
  DISCOURSE_SMTP_OPENSSL_VERIFY_MODE: none
  DISCOURSE_SMTP_ENABLE_START_TLS: false

Note that if I omit the DISCOURSE_SMTP_USER_NAME or DISCOURSE_SMTP_PASSWORD variables, your install script yells at me stating that they’re required (bug?).

And now when I click the “Resend Activation Email” button in the Discourse wui, this entry pops-up in the log file (/var/discourse/shared/standalone/log/rails/production.log):

Started PUT "/finish-installation/resend-email" for 127.0.0.1 at 2019-11-07 13:15:31 +0000
Processing by FinishInstallationController#resend_email as HTML
  Parameters: {"authenticity_token"=>"SzQCvRWiqdXsBKzOjIB0X7KkvXro7Od6SdP8Qa8vvrskPeNYZNos5ORHJfyDUrHiKShZR/txM6NHuqHHCQCR1w=="}
  Rendering finish_installation/resend_email.html.erb within layouts/finish_installation
  Rendered finish_installation/resend_email.html.erb within layouts/finish_installation (Duration: 0.7ms | Allocations: 103)
  Rendered layouts/_head.html.erb (Duration: 0.5ms | Allocations: 103)
Completed 200 OK in 98ms (Views: 3.0ms | ActiveRecord: 0.0ms | Allocations: 4763)
  Rendering layouts/email_template.html.erb
  Rendered layouts/email_template.html.erb (Duration: 0.5ms | Allocations: 141)
Delivered mail c4ca58ca-345e-46c4-81bc-6d0eac7afa04@discourse.opensourceecology.org (11.3ms)
Job exception: wrong authentication type none

…But my authentication type is ‘none’. What should the correct setting be for no authentication?

EDIT: also, can someone link me to the doc that defines all of the possible “DISCOURSE_SMTP_*” variables and all of their valid values?

EDIT2: this is proving to be far more difficult than it should be. I think ‘localhost’ is resolving inside the docker container to the Discourse docker container itself (app) – not the docker host that is running my postfix smtp server. That’s further complicated by postfix’s mynetworks and iptables (which were configured by the discourse-setup script or its children scripts). What’s the correct config here to just have Discourse use the smtp server on which I want to run Discourse, with no smtp auth?

1 « J'aime »

I think that hasn’t been very true for about 20 years.

You can’t use discourse-setup for situations like yours because few people have non password protected smtp servers, even behind a firewall.

What I would do is configure smtp passwords for my mail server. There really isn’t much downside.

If you don’t want to do that I think that instead of “none” for authentication you might want “” (and similarly for the password and username).

I think so too. You might try using the container name. I think that you need to see that they are both on the same docker network.

2 « J'aime »

In 2019, it’s the default config for postfix on RHEL/CentOS. Postfix binds only to the loopback interface and drops all smtp requests that don’t originate from 127.0.0.0/8. No auth required. I’m not sure about debian, but I’d imagine exim has a similar default config.

A couple relevant topics on these forums from other users who hit this issue:

There doesn’t appear to be a topic for how to set this up on RHEL/Cent OS with the necessary changes to both Discourse and postfix, so I’m documenting this here.

This does not appear to be possible with the discourse-setup script, but I did get this to work.

First, I had to figure out the IP address of the docker host as the docker container sees it. Using 127.0.0.1 won’t work because the docker container will see 127.0.0.1 as itself. Rather, we need to specify the IP address or hostname of the docker host that is running the postfix SMTP server, and one that is addressible by the docker container (so not your docker host’s Internet-facing IP address if you want your SMTP server to not be Internet-accessible, for example).

I extracted the relevant IP address of the docker host (172.17.0.1) from the docker0 interface by executing this on the docker host:

[maltfield@osestaging1 ~]$ ip address show docker0
3: docker0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP 
    link/ether 02:42:80:35:65:a1 brd ff:ff:ff:ff:ff:ff
    inet 172.17.0.1/16 brd 172.17.255.255 scope global docker0
       valid_lft forever preferred_lft forever
    inet6 fe80::42:80ff:fe35:65a1/64 scope link 
       valid_lft forever preferred_lft forever
[maltfield@osestaging1 ~]$

Then I edited my Discourse app’s yaml file, setting the “DISCOURSE_SMTP_ADDRESS” to 172.17.0.1 from above.

[maltfield@osestaging1 ~]$ cd /var/discourse/
[maltfield@osestaging1 discourse]$ grep SMTP containers/app.yml
  DISCOURSE_SMTP_ADDRESS: 172.17.0.1
  DISCOURSE_SMTP_PORT: 25
  DISCOURSE_SMTP_AUTHENTICATION: none
  DISCOURSE_SMTP_OPENSSL_VERIFY_MODE: none
  DISCOURSE_SMTP_ENABLE_START_TLS: false
[maltfield@osestaging1 discourse]$ 

Note that I first tried to use the internal docker hostname host.docker.internal for this, but apparently this hostname isn’t available to linux docker users

Because the default postfix configuration in RHEL/Cent OS binds only to 127.0.0.1 (which is good), you’ll need to change /etc/postfix/main.cf so it also binds to the docker0 interface and add that subnet to the mynetworks group so that SMTP traffic coming from docker containers will be accepted by postfix.

[maltfield@osestaging1 postfix]$ grep -ir '172.17' /etc/postfix/*
/etc/postfix/main.cf:inet_interfaces = 127.0.0.1, 172.17.0.1
/etc/postfix/main.cf:mynetworks = 127.0.0.0/8, 172.17.0.0/16
[maltfield@osestaging1 postfix]$ 

After those changes, rebuild Discourse and it should now be able to send emails out through your docker host’s postfix.

/var/discourse/launcher rebuild app

While this works, I have a few questions:

  1. Is there some other environment variable or hostname that already points to the docker host (172.17.0.1 in this case)?

I noticed that there is a DISCOURSE_HOST_IP environment variable “injected” by launcher. Is it possible to set this DISCOURSE_SMTP_ADDRESS yaml key to the same value as the other’s yaml key with something like this?

DISCOURSE_SMTP_ADDRESS: $DISCOURSE_HOST_IP
  1. In general, how durable is the 172.17.0.1 IP of the docker host? Is it always this IP on RHEL/Cent OS systems? Will it ever change on me?
3 « J'aime »

@maltfield Just wanted to say thank you for the instructions.

I ran into same issue on Debian… Could create a separate mail user for Discourse I suppose and have it connect and log in to site:465 but connecting to port 25 from the inside is more logical, in my opinion.

And by the way, on Debian 10 with docker.io from the repositories - docker0 is still 172.17.0.1/16.

Maybe you are misunderstanding what @maltfield is saying?

For as long as I can remember (which goes further back than 20 years), Linux ( / Unix / BSD / Solaris) systems have an SMTP server running which is configured by default to be happy to relay anything received from localhost without any questions. This relieves any other application running on that machine from having to worry about and configure SMTP settings themselves.

2 « J'aime »

Yes, most linux servers don’t require auth to send mail (either by default or after installl & configuring). Nor is it necessary if they don’t relay from anywhere but the local network. The default Discourse install scripts won’t work for most servers. It’s designed for a narrow set of docker-based cloud solutions.

You can read my full comprehensive instructions for installing Discourse on a dedicated, baremetal server running RHEL/CentOS 7 on the Open Source Ecology wiki. Note the section on SMTP here:

2 « J'aime »

Well, I almost always defer to you on such matters! I guess it’s been a good number of years since I’ve run an SMTP server on localhost, so it’s a good bet that I don’t know what I’m talking about.

More evidence that I’m wrong! :man_shrugging:

Nice!

But discourse-setup is only ever going to be for people who know virtually nothing about system administration. If you know how to install an SMTP server, you can edit a yml file.

3 « J'aime »

If the host where the container is running has a name you can get via DNS, it works just to specify that:

DISCOURSE_SMTP_ADDRESS: real.machine.example.com

Postfix will still see that the source of the mail is local and handle it that way.

1 « J'aime »

Si DISCOURSE_HOSTNAME et DISCOURSE_SMTP_ADDRESS sont identiques, cela posera-t-il des problèmes ?

J’ai configuré Postfix et Dovecot sur l’hôte Docker pour accepter les requêtes authentifiées via TLS. J’ai des certificats valides pour mon serveur, mais quelle que soit la configuration que j’essaie, je n’arrive pas à faire en sorte que Discourse envoie correctement les e-mails à Postfix fonctionnant sur l’hôte Docker.

Si j’utilise le nom d’hôte (discourse.[monhote].com), cela ne fonctionne pas (il ne se connecte même pas). Si j’utilise l’adresse IP de l’hôte Docker (172.17.0.1), j’obtiens

le nom d'hôte « 172.17.0.1 » ne correspond pas au certificat du serveur

Clairement, je dois utiliser le FQDN qui a été utilisé pour créer les certificats. Si j’essaie de définir DISCOURSE_SMTP_ENABLE_START_TLS sur false, il indique que je dois émettre une commande start TLS. Je ne souhaite pas vraiment ouvrir Postfix sans TLS, donc je ne considère pas cela comme une option viable de toute façon.

L’utilisation d’un relais SMTP externe n’est pas non plus une option car je ne veux pas payer plus cher simplement pour m’assurer que les e-mails ne finissent pas dans les dossiers spam/junk des gens.

Je dois dire que je n’ai qu’une compréhension rudimentaire du réseau Docker, et encore moins de la configuration d’un serveur SMTP Postfix avec Dovecot pour l’authentification, mais je ne suis pas un débutant complet, et réussir cette configuration de manière sûre et sécurisée s’avère extrêmement difficile.

@maltfield J’ai lu votre article sur Open Source Ecology, mais je ne veux pas utiliser de connexion non authentifiée sur le port 25. L’université pour laquelle je travaille a des protocoles très stricts concernant l’utilisation de communications non chiffrées et non authentifiées (même au sein d’une configuration de réseau local comme celle-ci). Ils craignent trop que cela puisse être abusé par un étudiant mécontent.

1 « J'aime »

J’ai donc pensé qu’il y avait quelque chose de louche à utiliser le même nom d’hôte pour le serveur Discourse et le serveur SMTP.

Une enquête plus approfondie révèle que le conteneur Docker ajoute l’entrée suivante au fichier hosts :

172.17.0.2	discourse.[mydomain].com discourse

Ainsi, toute tentative d’utilisation du même nom d’hôte pour le conteneur en cours d’exécution et l’hôte Docker entraînera l’envoi de toutes les requêtes émises par le conteneur vers le conteneur lui-même et non vers l’hôte Docker.

Quel fiasco ! Pourquoi Discourse ne fournit-il pas un serveur SMTP configuré par défaut dans le conteneur ?!
OU rend-il plus facile l’utilisation de Discourse sans Docker !

Deux jours de ma vie perdus à cause de ce problème.

En fin de compte, j’accepte le fait que je ne peux pas utiliser TLS pour communiquer avec le SMTP s’exécutant sur l’hôte Docker (sans obtenir de certificats en utilisant un autre nom d’hôte). Pour que cela fonctionne enfin, j’ai dû m’assurer que 172.17.0.0/16 est ajouté à la variable mynetworks dans le fichier main.cf de Postfix :

mynetworks = 127.0.0.0/8 [::ffff:127.0.0.0]/104 [::1]/128 172.17.0.0/16

Cela permet à Postfix de considérer tout conteneur Docker s’exécutant sur ce serveur comme faisant partie du réseau.

Un autre changement que j’ai dû apporter a été de m’assurer que smtpd_sasl_security_options est défini sur noanonymous pour empêcher les « étrangers » d’utiliser Postfix comme relais SMTP. Assurez-vous que l’option noplaintext n’est pas définie ici, sinon Postfix n’autorisera l’authentification qu’avec TLS.

smtpd_sasl_security_options = noanonymous

Avec ces paramètres de configuration, j’ai pu spécifier les paramètres suivants dans app.yml :

  DISCOURSE_SMTP_ADDRESS: 172.17.0.1                            # IP address of the Docker host (as seen from within this container)
  DISCOURSE_SMTP_PORT: 25
  DISCOURSE_SMTP_USER_NAME: discourse
  DISCOURSE_SMTP_PASSWORD: pa$$word
  DISCOURSE_SMTP_ENABLE_START_TLS: false                        # (optional, default true)
  DISCOURSE_SMTP_DOMAIN: discourse.[mydomian].com                # (required by some providers)
  DISCOURSE_NOTIFICATION_EMAIL: noreply@discourse.[mydomain].com # (address to send notifications from)

J’ai également créé un compte utilisateur local sur l’hôte Docker dans le seul but de l’authentification SASL.
Avec ces changements, j’ai finalement pu envoyer des e-mails depuis le conteneur, mais j’ai l’impression que c’est une configuration sous-optimale. Idéalement, il devrait être possible d’utiliser le nom d’hôte souhaité pour l’hôte Docker et que les requêtes à discourse.[mydomain].com aboutissent au bon endroit.

Maintenant, je dois configurer SPF et DKIM pour que les e-mails atterrissent dans les boîtes de réception des gens (au lieu de leurs dossiers spam). J’espère vraiment qu’un jour ce processus douloureux sera plus automatisé. Peut-être fournir des instructions sur la façon de configurer Discourse sans utiliser Docker (afin qu’il puisse être utilisé avec cPanel par exemple…) ou rendre la configuration des e-mails moins pénible en fournissant une sorte de configuration SMTP par défaut directement dans le conteneur Docker !

2 « J'aime »

Si vous revenez au début des années 1990, c’était comme vous le souhaitez. Les choses dont vous parlez fonctionnaient simplement. Mais les spammeurs ont rendu les choses beaucoup plus compliquées. Le processus ne fera que devenir plus difficile, c’est pourquoi la recommandation est d’utiliser un service qui s’occupe de nombreuses complications pour vous.

2 « J'aime »

Je suis content que votre configuration de messagerie fonctionne !

Il y a eu des mises à jour du guide de dépannage de la messagerie depuis hier. Si vous n’êtes toujours pas satisfait de votre configuration de messagerie, essayez à nouveau !


Peut être résolu en utilisant :


… juste la résolution DNS par défaut du nom de domaine vers l’IP.

Ne vous méprenez pas. Je comprends l’importance de SPF et DKIM. C’est juste agaçant. J’aimerais juste que cela puisse être installé sur nos serveurs cPanel actuels où ce genre de choses est déjà configuré.

1 « J'aime »

C’est ce qui me manquait. Ça fonctionne maintenant avec TLS.

J’ai aussi configuré DKIM, donc les e-mails ne devraient plus être marqués comme spam.

2 « J'aime »