Mail client cannot connect to SMTP server

Nextcloud version: 27.1.3 (Snap)
Operating system and version: Ubuntu 22.04
Apache or nginx version: Don’t know
PHP version: Don’t know

I have just set up a new Nextcloud instance using the snap package and everything but the SMTP mailer works flawlessly. When I try to test my settings using the “send email” button, I always get the response

"A problem occurred while sending the email. Please revise your settings. (Error: Email could not be sent. Check your mail server log)"

… after some delay of ~10 seconds (timeout?).

Unfortunately I do not have access to the logs of the remote SMTP server but I verified that it is configured correctly by using the same SMTP credentials on other devices and testing services.

The SMTP server supports unencrypted/STARTTLS on ports 25/587 as well as SSL on port 465, but every configuration in Nextcloud yields the same result.

I have checked all the log files in /var/snap/nextcloud/current/logs, but pressing the “send email” button does not produce output in any of those files, despite 'mail_smptdebug' => true, (which is why I did not include log output here).

I suspect some kind of connectivity issues, which is why I tried telnetting into the SMTP server from the Nextcloud instance. For some reason, telnet seems to prefer an IPv6 connection which is not working (I don’t know why). After around a minute, the connection times out and telnet tries the servers IPv4 adress, which successfully connects.

root@cloud:~# telnet my.mail.server 25
Trying *IPv6 adress*...


Trying *IPv4 adress*...
Connected to my.mail.server.
Escape character is '^]'.
220 mail.server.alias ESMTP *provider information* Thu, 30 Nov 2023 18:40:55 +0100
250-mail.server.alias Hello cloud.server.alias [*cloud server ip*]
250-SIZE 52428800
250 HELP

My hypothesis is that the Nextcloud instance is having the same issues when trying to connect to the SMTP server through IPv6, but I don’t know how to confirm this due to the lack of logging output.

Is there some way to force the Nextcloud SMTP client to use IPv4? Or can I reconfigure my system so that it prefers IPv4 connections over IPv6 in general?

Thanks in advance for any help!


but notice the changes to restore them later, if it does not help.

1 Like

That did the trick!

(I permanently disabled IPv6 by reconfiguring grub)

I tried adding

net.ipv6.conf.all.disable_ipv6 = 1
net.ipv6.conf.default.disable_ipv6 = 1
net.ipv6.conf.lo.disable_ipv6 = 1
net.ipv6.conf.tun0.disable_ipv6 = 1

in /etc/sysctl.conf before, but that didn’t help.

Thanks a lot!

Maybe your network (router) cannot forward IPv6-requests to internet. So requests to the mail server run into “nothing”.

Sounds plausible.

But then why would the router lease IPv6 adresses to my devices…?
Topic for another day/thread :smiley:

Thanks again for the help :slight_smile:

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