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:
- Install the AIO Nextcloud on linode market place and use a custom domain you own
- Put either google or fastmail smtp URLs with your proper credentials
- Hit “Send email” button
- 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 meansnextcloud.log
and you would actually need theloglevel = 0
to be set inconfig.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
orsmtp.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.