Nextcloud AIO Email Error

System Information

Nextcloud version: 30.0.0 Hub 9
AIO Docker: Ubuntu 22.04.5 LTS
PHP version (eg, 8.3): 8.2.23

The issue you are facing:
The “Email server” doesn’t successfully test and verify email.

Is this the first time you’ve seen this error? (Y/N): Yes

Steps to replicate it:

  1. Install the AIO Nextcloud on linode market place and use a custom domain you own
  2. Put either google or fastmail smtp URLs with your proper credentials
  3. Hit “Send email” button
  4. Fail with unhelpful message: A problem occurred while sending the email. Please revise your settings. (Error: Email could not be sent. Check your mail server log) - since there is no “mail server log”, you have to chase down it means nextcloud.log and you would actually need the loglevel = 0 to be set in config.php to even see an error(s).

Mail Issue

First things first, I have googled and read nearly all documentation on nextcloud email, forum nextcloud email issues, and as much AIO container specific stuff I could that would relate to email. None of that seemed to pertain the issues I am encountering.

I am receiving this error every time I try to send a test email via the “Email server” in “Basic settings”:

Connection could not be established with host .... Operation timed out

The following options can be set for the “Email server” and these are all the variations I chose:

  • Send mode: SMTP
  • Encryption: SSL or None/STARTTLS
  • From address: nextcloud@<mydomain>
  • Server address: smtp.fastmail.com or smtp.gmail.com and matching port (465 or 587)
  • Authentication:
    • fastmail/gmail username
    • fastmail/gmail password

Once I found the correct log and turned debug logging on, these are the errors I saw:

# Google SSL
"exception": {
    "Exception": "Symfony\\Component\\Mailer\\Exception\\TransportException",
    "Message": "Connection could not be established with host \"ssl://smtp.gmail.com:465\": stream_socket_client(): Unable to connect to ssl://smtp.gmail.com:465 (Operation timed out)",
    "Code": 0,
    "Trace": [

# Google None/STARTTLS
"exception": {
    "Exception": "Symfony\\Component\\Mailer\\Exception\\TransportException",
    "Message": "Connection could not be established with host \"smtp.gmail.com:587\": stream_socket_client(): Unable to connect to smtp.gmail.com:587 (Operation timed out)",
    "Code": 0,
    "Trace": [

# Fastmail SSL
"exception": {
    "Exception": "Symfony\\Component\\Mailer\\Exception\\TransportException",
    "Message": "Connection could not be established with host \"ssl://smtp.fastmail.com:465\": stream_socket_client(): Unable to connect to ssl://smtp.fastmail.com:465 (Operation timed out)",
    "Code": 0,
    "Trace": [

# Fastmail None/STARTTLS
"exception": {
    "Exception": "Symfony\\Component\\Mailer\\Exception\\TransportException",
    "Message": "Connection could not be established with host \"smtp.fastmail.com:587\": stream_socket_client(): Unable to connect to smtp.fastmail.com:587 (Operation timed out)",
    "Code": 0,
    "Trace": [

I left out the “Trace” since it is just the php exception stack and nothing noteworthy. I will also spare the other variations of the “Email server” options as they all error with a connection/operation error as well.

Docker Container and Netcat

The AIO container can connect to those urls and ports successfully:

eff988efec82:/var/www/html# nc -v -u smtp.fastmail.com 587
Connection to smtp.fastmail.com (103.168.172.45) 587 port [udp/*] succeeded!

eff988efec82:/var/www/html# nc -v -u smtp.fastmail.com 465
Connection to smtp.fastmail.com (103.168.172.45) 465 port [udp/*] succeeded!

eff988efec82:/var/www/html# nc -v -u smtp.gmail.com 465
Connection to smtp.gmail.com (173.194.202.109) 465 port [udp/*] succeeded!

eff988efec82:/var/www/html# nc -v -u smtp.gmail.com 587
Connection to smtp.gmail.com (173.194.202.109) 587 port [udp/*] succeeded!

and all URLs are pingable so it doesn’t appear to be a routing issue via the container → host machine → internet.

What Next?

What should I troubleshoot next? It is an Alpine Linux v3.20 container, but it is unclear to me how it is actually sending mail. Is it all done through PHP code and modules? In the exception trace I see:

  • SocketStream.php
  • SmtpTransport.php

so I am assuming PHP through code could create and use a Linux socket to create an email and send it. However, it seems unlikely I should have to troubleshoot PHP code to find why the email test is failing.
The nextcloud instance has correct certs and the custom domain is setup correctly so I don’t think that is the issue.

Any help would be greatly appreciated.

Did you find solution? i have same issue with outlook.com.
/var/www/html # nc -v -u smtp-mail.outlook.com 587
Connection to smtp-mail.outlook.com (52.96.230.246) 587 port [udp/*] succeeded!

but still failed to send email

I tried another SMTP server and works. like Login - MailerSend

No I haven’t found a solution yet. I would think 2 major email providers, whom both offer smtp services for this exact purpose, should work so I’d prefer not to play service whack-a-mole until some random provider works.

If for some reason Google and Fastmail do not work, I’d like to know the reason why so I can choose a proper provider that does work.

Also I assume I am doing something obviously wrong since this is a very simple and well known service (sending email through smtp). Hopefully someone notices it or points me in the direction of something I have misconfigured or setup incorrectly.

You’re testing with UDP which isn’t a valid test. Remove -u.

Well that is embarrassing. You are absolutely correct that I was inadvertently testing with UDP and I should have caught that earlier.

Continued Investigation

I kept investigating and this is what I found:

Local

From my local laptop I could successfully connect to fastmail servers as expected

local-laptop:~> telnet smtp.fastmail.com 587                                                                                                                                         
Trying 103.168.172.60...
Connected to smtp.fastmail.com.
Escape character is '^]'.
220 smtp.fastmail.com ESMTP ready

Docker Container & Linode Instance

However, from within the docker container and on the nextcloud instance:

# Docker container
:~> nc -v smtp.fastmail.com 587
nc: connect to smtp.fastmail.com (103.168.172.60) port 587 (tcp) failed: Operation timed out

# Nextcloud instance
root@nextcloud:~> telnet smtp.fastmail.com 587
Trying 103.168.172.45...
^C

I am unable to connect, also as expected (since that is the issue I have been having).

UFW Maybe?

The ufw firewall was on so I thought maybe that was it. I turned it off and recieved the same timeout issues.

What the Actual Problem Is

Linode, in an effort to fight spam, decided to block all customers from sending email from any VPS if you are a customer after 2019. Blog post is here.

As an aside, you would think you could side step this by using the fastmail proxy server here.
So in the docker container:

:~> nc -v smtps-proxy.fastmail.com 80
Connection to smtps-proxy.fastmail.com (103.168.172.27) 80 port [tcp/http] succeeded!

connectivity looks good, but no matter what I put in the Nextcloud “Email server” options it always fails with:

"Message": "Connection to \"smtps-proxy.fastmail.com:80\" timed out."

I sent a support ticket to linode to allow smtp for my nextcloud instance. I will report back here once the respond and I get it working.

1 Like

Were you able to resolve this issue with the mail server options?

Bump.

I am experiencing the same issue on Nextcloud AIO.

I’ve used the exact same settings from another Nextcloud instance where the email settings and test are successful.

Are the mentioned outgoing ports above (587…) open in your firewall?
Some providers (outlook.com, Google?? etc.) need OAuth to login.
Some providers (gmail etc.) need granted permission to 3rd party mail-clients (other than gmail-app) to be set in your Google account.
The email SSL-certificate must be valid (self-signed may be rejected - but I am not sure).

Running both

nc -v smtp.gmail.com 465

and

nc -v smtp.gmail.com 465

return successful connections.

As mentioned, I’m using the exact same settings for email server from another Nextcloud instance and have no issues there.

Hi, have you already tried enabling ipv6-support in docker? See all-in-one/docker-ipv6-support.md at main · nextcloud/all-in-one · GitHub

Apologies for the absence, many things came up. I made a little more progress that was specific to my setup.

Where I am at

As pointed out above, the reason the email was being prevented from sending within the Nextcloud GUI (AIO) was due to Linode preventing email on VPSes to fight spam.

Therefore it had nothing to due with the firewall, configs, MX/TXT, etc. I had everything set up correctly Nextcloud wise.

What Is Still Wrong?

After sending the email successfully from Nextcloud, I receive it in fastmail, but I get the “Mail Delivery System” bounce back error.

Likely I have something misconfigured either in fastmail or my registrar for my domain with email routing or something. When I figure that out, I can reply back here.

1 Like

Secondary Issue for Email

It ended up being a misconfiguration in my registrar for email forwarding, my custom name servers, and the way they automatically did MX and TXT records. I had to specifically add their email forwarders as MX records to my DNS domain in Linode.

This shouldn’t affect anyone unless they setup their Nextcloud (AIO) in Linode with a custom domain and then use the Linode name servers in the registrar for your domain and set up email forwarding to your desired email address on that registrar. I wrote that terribly, but hopefully it makes sense. :smile:

1 Like