Cannot Connect to Postfix

Having trouble getting Mattermost to connect to Postfix. I’ve read the other threads I’ve been able to find, but so far I haven’t found anything that seems to be helping. Looking for some assistance in figuring out what I have wrong.

OS = Ubuntu 22.04.4 LTS

Mattermost is installed via apt, version 9.8.1-0

Postfix installed via apt, version 3.6.4-1ubuntu1.3

DNS entries for domain are all set and I can send an email via the CLI. But not matter what I put in the Mattermost SMTP settings I can’t get the test connection button to be successful.

My understanding is that by using localhost in the SMTP Host field it should not go through the NIC and not be subject to firewall rules, though I have also tried to opening up the various ports in UFW (25/587) and no change.

Right now I have the following entries in place:

SMTP Server: localhost
SMTP Server Port: 25
Enable SMTP Authentication: false
Connection Security: None
Skp Server Certificate Verification: true
Enable Security Alerts: true

When I hit the test connection button I get:

Connection unsuccessful: Connection unsuccessful: unable to connect to the SMTP server: context deadline exceeded.

I’ve tried changing each of these settings and no matter what settings I use I can’t get this to connect and I’m pretty much at a loss as to what I’ve got configured wrong.

I do notice in the log entry that even though I am using localhost that it shows the IP address as 127.0.0.1.

I would appreciate any suggestions on things to try or additional things to look at.

Here is the full log event:

{
  "caller": "web/context.go:115",
  "err_where": "testEmail",
  "error": "testEmail: Connection unsuccessful: unable to connect to the SMTP server: context deadline exceeded",
  "http_code": 500,
  "ip_addr": "127.0.0.1",
  "level": "error",
  "method": "POST",
  "msg": "Connection unsuccessful: unable to connect to the SMTP server: context deadline exceeded",
  "path": "/api/v4/email/test",
  "request_id": "5uxqwoun8jrjzpfwd4gejkuh6a",
  "timestamp": "2024-06-09 10:53:29.973 Z",
  "user_id": "ky7ugi39538j8g9ubi61y4mdcr"
}

On that host, can you nc localhost 25 ? What do the postfix logs say? What does systemctl status postfix.service return?

I’m not familiar with the nc command. This is ncat? I think what you asked me to run should start a chat server? When I execute that command it doesn’t provide any output, no error or anything. If I press enter again or cntrl-c, I just drop back to my prompt.

Here are the most recent lines from the mail.log file. Maybe I need to look at SASL configuration?

Jun 10 22:09:30 www postfix/anvil[19515]: statistics: max connection count 1 for (smtp:::1) at Jun 10 22:07:49
Jun 10 22:09:30 www postfix/anvil[19515]: statistics: max cache size 1 at Jun 10 22:07:49
Jun 10 22:09:58 www postfix/smtpd[19550]: connect from localhost[::1]
Jun 10 22:09:58 www postfix/smtpd[19550]: warning: SASL: Connect to private/auth failed: No such file or directory
Jun 10 22:09:58 www postfix/smtpd[19550]: fatal: no SASL authentication mechanisms
Jun 10 22:09:59 www postfix/master[1478]: warning: process /usr/lib/postfix/sbin/smtpd pid 19550 exit status 1
Jun 10 22:09:59 www postfix/master[1478]: warning: /usr/lib/postfix/sbin/smtpd: bad command startup -- throttling
Jun 10 22:11:39 www postfix/anvil[19552]: statistics: max connection rate 1/60s for (smtp:::1) at Jun 10 22:09:58
Jun 10 22:11:39 www postfix/anvil[19552]: statistics: max connection count 1 for (smtp:::1) at Jun 10 22:09:58
Jun 10 22:11:39 www postfix/anvil[19552]: statistics: max cache size 1 at Jun 10 22:09:58
Jun 10 22:16:40 www postfix/smtpd[20090]: connect from localhost[::1]
Jun 10 22:16:40 www postfix/smtpd[20090]: warning: SASL: Connect to private/auth failed: No such file or directory
Jun 10 22:16:40 www postfix/smtpd[20090]: fatal: no SASL authentication mechanisms
Jun 10 22:16:41 www postfix/master[1478]: warning: process /usr/lib/postfix/sbin/smtpd pid 20090 exit status 1
Jun 10 22:16:41 www postfix/master[1478]: warning: /usr/lib/postfix/sbin/smtpd: bad command startup -- throttling
Jun 10 22:17:41 www postfix/smtpd[20135]: connect from localhost[::1]
Jun 10 22:17:41 www postfix/smtpd[20135]: warning: SASL: Connect to private/auth failed: No such file or directory
Jun 10 22:17:41 www postfix/smtpd[20135]: fatal: no SASL authentication mechanisms
Jun 10 22:17:42 www postfix/master[1478]: warning: process /usr/lib/postfix/sbin/smtpd pid 20135 exit status 1
Jun 10 22:17:42 www postfix/master[1478]: warning: /usr/lib/postfix/sbin/smtpd: bad command startup -- throttling

Here is the postfix service status.

● postfix.service - Postfix Mail Transport Agent
     Loaded: loaded (/lib/systemd/system/postfix.service; enabled; vendor preset: enabled)
     Active: active (exited) since Sat 2024-06-08 23:39:33 UTC; 1 day 22h ago
       Docs: man:postfix(1)
   Main PID: 1479 (code=exited, status=0/SUCCESS)
        CPU: 699us

Jun 08 23:39:33 jed-01 systemd[1]: Starting Postfix Mail Transport Agent...
Jun 08 23:39:33 jed-01 systemd[1]: Finished Postfix Mail Transport Agent.

Your postfix is immediately bombing out due to SASL not working. I’d start by disabling it…

smtp_sasl_auth_enable = no
smtp_sender_dependent_authentication = no

Restart postfix.service and try again. Assuming that works, if you need SASL, I’d start from the beginning and work and test until it’s right. Postfix SASL Howto

1 Like

Thanks so much. I’m getting a different error now, it looks like access denied now.

In Mattermost when I test the connection I’m getting this error immediately:

Connection unsuccessful: Connection unsuccessful: failed to set the to address: 454 4.7.1 ottomation@pm.me: Relay access denied

And my postfix log shows:

Jun 10 22:40:21 www postfix/postfix-script[21013]: stopping the Postfix mail system
Jun 10 22:40:21 www postfix/master[20939]: terminating on signal 15
Jun 10 22:40:22 www postfix/postfix-script[21584]: starting the Postfix mail system
Jun 10 22:40:22 www postfix/master[21586]: daemon started -- version 3.6.4, configuration /etc/postfix
Jun 10 22:40:26 www postfix/smtpd[21599]: connect from localhost[::1]
Jun 10 22:40:26 www postfix/smtpd[21599]: NOQUEUE: reject: RCPT from localhost[::1]: 454 4.7.1 <ottomation@pm.me>: Relay access denied; from=<admin@jedomation.com> to=<ottomation@pm.me> proto=ESMTP helo=<chat.jedomation.com>
Jun 10 22:40:26 www postfix/smtpd[21599]: lost connection after RCPT from localhost[::1]
Jun 10 22:40:26 www postfix/smtpd[21599]: disconnect from localhost[::1] ehlo=1 mail=1 rcpt=0/1 commands=2/3

I found a typo in my config file for mynetworks. That appears to have gotten rid of the access denied error.

Now I get:

Connection unsuccessful: Connection unsuccessful: failed to set the to address: 451 4.3.5 Server configuration error

And the postfix log:

Jun 10 22:48:38 www postfix/master[24132]: daemon started -- version 3.6.4, configuration /etc/postfix
Jun 10 22:48:41 www postfix/smtpd[24145]: connect from localhost[::1]
Jun 10 22:48:41 www postfix/smtpd[24145]: warning: unknown smtpd restriction: "premit"
Jun 10 22:48:41 www postfix/smtpd[24145]: NOQUEUE: reject: RCPT from localhost[::1]: 451 4.3.5 Server configuration error; from=<admin@jedomation.com> to=<ottomation@pm.me> proto=ESMTP helo=<chat.jedomation.com>
Jun 10 22:48:41 www postfix/smtpd[24145]: lost connection after RCPT from localhost[::1]
Jun 10 22:48:41 www postfix/cleanup[24149]: 87E595FC47: message-id=<20240610224841.87E595FC47@jed-01.jedomation.com>
Jun 10 22:48:41 www postfix/qmgr[24134]: 87E595FC47: from=<double-bounce@jedomation.com>, size=1020, nrcpt=1 (queue active)
Jun 10 22:48:41 www postfix/smtpd[24145]: disconnect from localhost[::1] ehlo=1 mail=1 rcpt=0/1 commands=2/3
Jun 10 22:48:47 www postfix/smtp[24150]: 87E595FC47: to=<postmaster@jedomation.com>, orig_to=<postmaster>, relay=mail.protonmail.ch[185.70.42.128]:25, delay=6.3, delays=0.01/0.01/6.1/0.13, dsn=5.1.1, status=bounced (host mail.protonmail.ch[185.70.42.128] said: 550 5.1.1 <postmaster@jedomation.com>: Recipient address rejected: Address does not exist (in reply to RCPT TO command))
Jun 10 22:48:47 www postfix/cleanup[24149]: DE9615FC69: message-id=<20240610224847.DE9615FC69@jed-01.jedomation.com>
Jun 10 22:48:47 www postfix/bounce[24152]: 87E595FC47: sender non-delivery notification: DE9615FC69
Jun 10 22:48:47 www postfix/qmgr[24134]: DE9615FC69: from=<>, size=3266, nrcpt=1 (queue active)
Jun 10 22:48:47 www postfix/qmgr[24134]: 87E595FC47: removed
Jun 10 22:48:54 www postfix/smtp[24150]: DE9615FC69: to=<double-bounce@jedomation.com>, relay=mail.protonmail.ch[185.70.42.128]:25, delay=6.8, delays=0/0/6.7/0.12, dsn=5.1.1, status=bounced (host mail.protonmail.ch[185.70.42.128] said: 550 5.1.1 <double-bounce@jedomation.com>: Recipient address rejected: Address does not exist (in reply to RCPT TO command))
Jun 10 22:48:54 www postfix/qmgr[24134]: DE9615FC69: removed

It looks like it’s saying that the recipient email address was rejected because it doesn’t exist. But it does, and I can send an email to that address using the mail command from the command line.

YES! Thank so much for your help!

I found another typo in my smtpd_recipient_restrictions line and it connected and successfully sent an email! Still went to spam, but at least it sends now.

Thank you very much, I appreciate you taking the time to help me!