# SMTP-config voor localhost of 172.17.0.1 werkt niet, hoe te debuggen

**URL:** https://meta.discourse.org/t/smtp-config-to-use-localhost-or-172-17-0-1-is-not-working-how-to-debug/229056
**Category:** Support
**Created:** [5 juni 2022 om 10:17 UTC](https://meta.discourse.org/t/smtp-config-to-use-localhost-or-172-17-0-1-is-not-working-how-to-debug/229056 "2022-06-05T10:17:45Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![meglio](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/meglio/32/71444_2.png) [@meglio](https://meta.discourse.org/u/meglio)
#### Post date: [5 juni 2022 om 10:17 UTC](https://meta.discourse.org/t/smtp-config-to-use-localhost-or-172-17-0-1-is-not-working-how-to-debug/229056/1 "2022-06-05T10:17:46Z")

</div>

Continuing the discussion from [How to set SMTP config to use localhost?](https://meta.discourse.org/t/how-to-set-smtp-config-to-use-localhost/131464/8):

> [@How to set SMTP config to use localhost?](https://meta.discourse.org/t/how-to-set-smtp-config-to-use-localhost/131464/8):
>
> Just to document here, the following was sufficient (all other SMTP lines commented out) to deliver to the docker host’s smtp server if no auth is necessary:
> 
> ```plaintext
> DISCOURSE_SMTP_ADDRESS: 172.17.0.1
> DISCOURSE_SMTP_PORT: 25
> 
> ```

I’m trying to connect to Protonmail Bridge running at the host machine, and it fails with `connection refused`. My settings are:

```plaintext
  DISCOURSE_SMTP_ADDRESS: 172.17.0.1
  DISCOURSE_SMTP_PORT: 1025

```

Now, nmap tests:

`nmap 127.0.0.1` on the host machine outputs:

```plaintext
Nmap scan report for localhost (127.0.0.1)
Host is up (0.000010s latency).
Not shown: 997 closed ports
PORT STATE SERVICE
22/tcp open ssh
1025/tcp open NFS-or-IIS
1042/tcp open afrog

```

`nmap 172.17.0.1` in the docker container does not output any 1025 port

I also tried in my `app.yml` file, in `expose` section:

```plaintext
172.17.0.1:1025:1025

```

But then the docker container failed to start erroring “the port is already in use”.

Finally, if I try to connect with using openssl from localhost:

`openssl s_client -connect 127.0.01:1025 -starttls smtp `

it works fine; but not when I try to from the docker container:

`openssl s_client -connect 172.17.0.1:1025 -starttls smtp `

Checking with `ss` on host machine:

```plaintext
ss -plnt
State Recv-Q Send-Q Local Address:Port Peer Address:Port Process
LISTEN 0 4096 127.0.0.1:1025 0.0.0.0:* users:(("proton-bridge",pid=953,fd=12))

```

What am I doing wrong?

* * *

One thing I found in [this stackoverflow answer](https://stackoverflow.com/a/31328031/335304) says:

> - you will only be able to access host services that are either (a) listening on `INADDR_ANY` (aka 0.0.0.0) or that are explicitly listening on the `docker0` interface.

Firstly, I checked `iptables --list`, which I believe gives default output:

```plaintext
iptables --list
Chain INPUT (policy ACCEPT)
target prot opt source destination

Chain FORWARD (policy DROP)
target prot opt source destination
DOCKER-USER all -- anywhere anywhere
DOCKER-ISOLATION-STAGE-1 all -- anywhere anywhere
ACCEPT all -- anywhere anywhere ctstate RELATED,ESTABLISHED
DOCKER all -- anywhere anywhere
ACCEPT all -- anywhere anywhere
ACCEPT all -- anywhere anywhere

Chain OUTPUT (policy ACCEPT)
target prot opt source destination

Chain DOCKER (1 references)
target prot opt source destination
ACCEPT tcp -- anywhere 172.17.0.2 tcp dpt:https
ACCEPT tcp -- anywhere 172.17.0.2 tcp dpt:http

Chain DOCKER-ISOLATION-STAGE-1 (1 references)
target prot opt source destination
DOCKER-ISOLATION-STAGE-2 all -- anywhere anywhere
RETURN all -- anywhere anywhere

Chain DOCKER-ISOLATION-STAGE-2 (1 references)
target prot opt source destination
DROP all -- anywhere anywhere
RETURN all -- anywhere anywhere

Chain DOCKER-USER (1 references)
target prot opt source destination
RETURN all -- anywhere anywhere

```

Now, I’m wondering if the Protonmail Bridge service that’s listening on `127.0.0.1:1025` is not accepting connections from the Docker container because they are not from `127.0.0.1` exactly?

---

<div class="post-metadata">

### Author: ![meglio](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/meglio/32/71444_2.png) [@meglio](https://meta.discourse.org/u/meglio)
#### Post date: [9 juni 2022 om 10:49 UTC](https://meta.discourse.org/t/smtp-config-to-use-localhost-or-172-17-0-1-is-not-working-how-to-debug/229056/2 "2022-06-09T10:49:40Z")

</div>

Turns out the traffic needs to be redirected, read more here:

> [@Use Protonmail Bridge with Discourse](https://meta.discourse.org/t/use-protonmail-bridge-with-discourse/229503):
>
> Problem: a) Protonmail Bridge cannot listen to IP other than 127.0.0.1, and b) Discourse in a Docker container cannot send SMTP requests to 127.0.0.1 of the host machine. Solution: We configure it to send to 172.17.0.1 (the Docker’s bridge IP on the host machine), and then redirect to 127.0.0.1, on which the Protonmail Bridge is listening. We do it with using Socat. How To Start by installing Socat: apt install socat We will run Socat as a service. Create service file: nano /etc/systemd/sy…

---

<div class="post-metadata">

### Author: ![system](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/system/32/443519_2.png) [@system](https://meta.discourse.org/u/system)
#### Post date: [9 juli 2022 om 10:49 UTC](https://meta.discourse.org/t/smtp-config-to-use-localhost-or-172-17-0-1-is-not-working-how-to-debug/229056/3 "2022-07-09T10:49:51Z")

</div>

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.
