Mattermost wont connect to postfix

Hi all!

I followed to set up mail notifications in my mattermost, which is run in a docker.

I also have postfix running, and can successfully send emails through it.

However, when I try to “test connection” in the email settings, I get this error in the logs

[2017/03/12 04:41:37 UTC] [EROR] /api/v3/admin/test_email:SendMail code=500 rid=cu7knu9z5tndpx8uii3mkbe3dc uid=77mxq5aib7y9jjjqkr4ppcrdea ip= Failed to open connection [details: dial tcp [::1]:25: getsockopt: connection refused]

I’m very stuck!

Thanks :slight_smile:

Is postfix running in docker also, or directly on the host system? If postfix is running in docker, is port 25 bound to the docker host system?

1 Like

Hi George,

No, postfix is running directly on the host. I don’t think 25 is bound to the docker – at least, I didn’t bind it.

I can send mail via postfix (routing thru Gmail SMTP) from the host via mail command.

I’m just using the postfix that came with OSX. I built the ‘production’ version of mattermost team for OSX as in the wiki, using docker compose method.

Is the ‘production’ version where I have gone awry? I haven’t set up any nodes to interconnect – I just used that method to get a feature-parity OSX install.


Thanks for providing that extra info. From what I can see so far, it appears that your postfix installation is working fine, as you have reported that you can send emails through it directly. However, Mattermost is unable to talk to it because it can’t open the TCP connection to it, as reported by the error you posted.

According to the error message, Mattermost is trying to connect to the IP address on port 25. Can you verify that your host system has that IP address on the “docker” network interface? And can you check that postfix is listening on that port on that IP address. I’m not familiar with OSX so I’m not sure exactly how you would check this. On Linux, you could run sudo ifconfig to check the first and sudo netstat -plnt for check the second - perhaps OSX is similar.

Possible issues I suspect might be the cause:

  1. postfix is only listening on “localhost”, ie. This means that the connection to it from the local mail command would work fine, as that connects to it locally, but the Mattermost container cannot connect to it because it is trying to reach it on the IP address

  2. (less likely than 1) Your docker network interface is listening on a different IP address thyan

1 Like

Thanks again!

I’ll have to recheck (docker not running atm; not at system), but I’m quite
sure that the IP address for docker interface is as it seems,

How might I get postfix to listen on Is there buried in postfix
cfg something to specify?

Actually, I think I did add the (or /17 or whichever it is to
expand out to .255.255) subnet to the postfix config. I think that was just
for send mail permission though – Will need to check that also.

Or I suppose I could map to local host:25 somehow…?

Much appreciate the help!

Not sure about how to configure postfix myself, but if you could paste the output of sudo netstat -plnt when you are back at the system that would allow us to confirm or rule out the listen address as the problem.

Ah, also, does that error mean mattermost is trying to send to, or is that just its from address? It’s not trying to open local host:25 / [::1]:25? (Which are the same, no?)

As you can tell, I’m not fluent in this stuff at all!


host:25 / [::1]:25 not the same, one is ipv4 the other ipv6, however from your error message it was trying to use the ipv6 address.

What is the value you have set for the SMTP Server configuration option in Mattermost?

Thank you both for your help so far!

Re postfix:

$ ps aux | grep ‘postfix|master’
_postfix 62853 0.0 0.0 2463172 3024 ?? S 1:19am 0:00.01 qmgr -l -t fifo -u
_postfix 62852 0.0 0.0 2454920 2968 ?? S 1:19am 0:00.01 pickup -l -t fifo -u -o content_filter=
root 62851 0.0 0.0 2454836 3000 ?? Ss 1:19am 0:00.02 master -e 60

and ports

$ sudo lsof -i -P | grep master
master 63047 root 13u IPv4 0x69f0b21b1f9d697b 0t0 TCP localhost:25 (LISTEN)
master 63047 root 14u IPv6 0x69f0b21b1bc8496b 0t0 TCP localhost:25 (LISTEN)
master 63047 root 26u IPv4 0x69f0b21b1fba6283 0t0 TCP localhost:587 (LISTEN)
master 63047 root 27u IPv6 0x69f0b21b1bc8292b 0t0 TCP localhost:587 (LISTEN)

Again, emails via the mail command are sent fine.

Meanwhile, mattermost:

$ docker ps
d13b4599f2ba mattermostdocker_web “/bin/sh -c /docke…” 9 days ago Up 17 minutes>80/tcp,>443/tcp mattermostdocker_web_1
aba0c7a80380 mattermostdocker_app “/ …” 9 days ago Up 17 minutes 80/tcp mattermostdocker_app_1
2b461e02d57d mattermostdocker_db “/docker-entrypoin…” 9 days ago Up 17 minutes 5432/tcp mattermostdocker_db_1


hayim$ docker exec d13b4599f2ba cat /etc/hosts localhost
::1 localhost ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters d13b4599f2ba

Finally, I appear to be able to access the host from within the docker:

root@d13b4599f2ba:/# ping
PING ( 56 data bytes
64 bytes from icmp_seq=0 ttl=37 time=0.757 ms
64 bytes from icmp_seq=1 ttl=37 time=0.475 ms
64 bytes from icmp_seq=2 ttl=37 time=0.471 ms
64 bytes from icmp_seq=3 ttl=37 time=0.506 ms
^C— ping statistics —
4 packets transmitted, 4 packets received, 0% packet loss
round-trip min/avg/max/stddev = 0.471/0.552/0.757/0.119 ms

In the System Console for my mattermost team I have
SMTP Server: localhost
SMTP Server Port: 25
Connection Security: None

which is a close as I could match to the instructions here. I have also tried in place of localhost.

So, to summarise:

  • postfix is working on the host, and listening on tcp:25
  • the docker container mattermost_docker_web_1 has address, and can ping the host
  • mail settings in the docker seem to be ok?


  • postfix is not listening on the docker’s IP… but should it be?
  • mattermost is trying to use the IPV6 address for localhost… is that an issue?
  • …??

Let me know if any further info would help! Thanks!!

Hmm… I have since found this: I tried that, but no dice. Not sure if I did everything right. Not sure if postfix is really listening on the alias’d port.

It seems getting OSX dockers to see the host is finnicky. There are other threads about how to access host services from OSX dockers, but I can’t seem to really understand.

If I built mattermost via docker-compose, how do I specify network settings, like -network=nat? Will have to understand this a bit better…!

Well your host service is listening on localhost aka so no you won’t be able to connect, you need to make it listen to given the link on your last message. That would create the ip on the loopback giving it access to your docker.

Ofc in your case you most likely want the ip to be something like or some other IP not in use.

On a previous message you said you were able to access the host at so instead of doing the above steps you can just add that IP to your postfix config and configure mattermost smtp to use it and again do the telnet below to ensure you can connect.

Also you might need to ensure the firewall is not blocking access to/from those ports on both. Some times by default the firewall will be blocking it…

So ping -c1 host, if u get the pings you can reach it, then telnet host 25 or 587 depending on what you want…

Thanks, prix.

I suspect that the ping test I posted above is bogus, because afterward I pinged all sorts of nonexistent addresses and all were successful, so long as the address was valid in form.

Is there anything in my docker’s hosts file that indicates that all addresses are forwarded back to the docker’s loopback?

Well, I am not familiar with docker so I can’t help you there, all I did was clear up the points related to postfix, based on what you have provided. In either case if you can issue a telnet host 25 from your docket and it doesn’t timeout, you’re green to go.

Hope it’s okay to revive this thread. I am running into the exact same problem as the original poster and I was wondering if @hayimd ended up finding a solution?

After some more poking around I got this to work.

For those who stumble across this issue looking for a fix, here is what I did.

_I am assuming you have gone through the basic Mattermost Docker installation, and have set up Postfix as a regular service on your host machine.

  1. On the host machine do ifconfig and find the ip address of the docker0 bridge network
  2. In Mattermost’s system console set up email notifications as per the docs under ‘Postfix’, but enter the ip address from step 1 in stead of localhost.
  3. Find the ip address of the mattermostdocker_web_1 container using this command: docker inspect -f '{{.Name}} - {{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' $(docker ps -aq)
  4. Add the ip address from step 3 into /etc/postfix/main to mynetworks, save the file and make sure you do service postfix restart
  5. Back in Mattermost, hit the ‘Test Connection’ button. The admin user should receive a test email from the configured from address.

I am no expert so I do not know if this is the ‘correct’ way to do this, but it works.

Thanks for posting back your solution @kaeru!

1 Like