Nextcloud in Docker not connecting to smtp email server on host network

[/details]

Some or all of the below information will be requested if it isn’t supplied; for fastest response please provide as much as you can. :heart:

The Basics

  • Nextcloud Server version (e.g., 29.x.x):
    • 31.0.0
  • Operating system and version (e.g., Ubuntu 24.04):
    • Ubuntu Server 22.04.5
  • Web server and version (e.g, Apache 2.4.25):
    • whatever is built into Nextcloud latest docker image
  • Reverse proxy and version _(e.g. nginx 1.27.2)
    • not used (local and VPN access only at present)
  • PHP version (e.g, 8.3):

  • Is this the first time you’ve seen this error? (Yes / No):
    • yes
  • When did this problem seem to first start?
    • as soon as sending an email for the first time was attempted
  • Installation method (e.g. AlO, NCP, Bare Metal/Archive, etc.)
    • Docker image
  • Are you using CloudfIare, mod_security, or similar? (Yes / No)
    • no

Summary of the issue you are facing:

Hey guys,

I’m pretty sure I haven’t seen a post regarding this on the forum. I have an instance of Nextcloud running in Docker (installed using Portainer). It is happily connected to a MariaDB database also running as a container in Docker.

I’m now trying to get the email alerts to work. What is interesting is that Gmail works with no issues so I know the Nextcloud config is correct, but we need to use a self-hosted SMTP email server on the same host network as the Docker installation. When I enter the local IP of the email server and the usual credentials that work on another application (Q-Sys) I get the following error message:

AxiosError: Request failed with status code 400

Nearly all of the forum posts seem to relate this error to not having an email address set up in the admin profile or having set up email information in docker-compose. Seeing as Gmail works I’m not sure these are relevant to the issue I am seeing.

If I connect to the container console I can ping the IP of the SMTP server, so it is visible on the network. Nextcloud is in Bridge mode for networking, but I would assume that any requests targeting ports 465 or 587 for email would still pass?

It may well be something on the email server causing the issue, but just wondered if anyone has seen issues before connecting to services on the host network from the bridged network, or has any thoughts on what it might be?

Steps to replicate it (hint: details matter!):

  1. configure email settings in basic settings:

Send Mode - SMTP
Encryption - SSL
From address alerts@[domain]
Server address [local IP of SMTP server]:465
Authentication - yes
Credentials - as per our Q-Sys email alerts that are working
3. press send email button
4. AxiosError: Request failed with status code 400 appears

Log entries

Nextcloud

No logs appear in relation to this issue

Web server / Reverse Proxy

Not used

Configuration

Nextcloud

{
“system”: {
“datadirectory”: “REMOVED SENSITIVE VALUE”,
“instanceid”: “REMOVED SENSITIVE VALUE”,
“passwordsalt”: “REMOVED SENSITIVE VALUE”,
“secret”: “REMOVED SENSITIVE VALUE”,
“trusted_domains”: [
“10.10.1.241”
],
“dbtype”: “mysql”,
“version”: “31.0.0.18”,
“overwrite.cli.url”: “https://10.10.1.241”,
“installed”: true,
“memcache.local”: “\OC\Memcache\APCu”,
“filelocking.enabled”: true,
“memcache.locking”: “\OC\Memcache\APCu”,
“upgrade.disable-web”: true,
“loglevel”: 2,
“maintenance”: false,
“maintenance_window_start”: 1,
“mail_smtpmode”: “smtp”,
“mail_sendmailmode”: “smtp”,
“mail_smtphost”: “REMOVED SENSITIVE VALUE”,
“mail_smtpauth”: true,
“mail_smtpname”: “REMOVED SENSITIVE VALUE”,
“mail_smtppassword”: “REMOVED SENSITIVE VALUE”,
“mail_smtptimeout”: 30,
“mail_smtpport”: “465”,
“default_phone_region”: “GB”,
“defaultapp”: “files”,
“app_install_overwrite”: ,
“dbname”: “REMOVED SENSITIVE VALUE”,
“dbhost”: “REMOVED SENSITIVE VALUE”,
“dbuser”: “REMOVED SENSITIVE VALUE”,
“dbpassword”: “REMOVED SENSITIVE VALUE”,
“mysql.utf8mb4”: true,
“mail_from_address”: “REMOVED SENSITIVE VALUE”,
“mail_domain”: “REMOVED SENSITIVE VALUE”,
“mail_smtpsecure”: “ssl”

Apps

Enabled:

  • app_api: 5.0.2
  • bruteforcesettings: 4.0.0
  • circles: 31.0.0-dev.0
  • cloud_federation_api: 1.14.0
  • dav: 1.33.0
  • federatedfilesharing: 1.21.0
  • federation: 1.21.0
  • files: 2.3.1
  • files_downloadlimit: 4.0.0
  • files_pdfviewer: 4.0.0
  • files_reminders: 1.4.0
  • files_sharing: 1.23.1
  • files_trashbin: 1.21.0
  • files_versions: 1.24.0
  • firstrunwizard: 4.0.0
  • groupfolders: 19.0.3
  • groupquota: 0.2.2
  • logreader: 4.0.0
  • lookup_server_connector: 1.19.0
  • notifications: 4.0.0
  • oauth2: 1.19.1
  • password_policy: 3.0.0
  • privacy: 3.0.0
  • profile: 1.0.0
  • provisioning_api: 1.21.0
  • related_resources: 2.0.0
  • serverinfo: 3.0.0
  • settings: 1.14.0
  • sharebymail: 1.21.0
  • support: 3.0.0
  • survey_client: 3.0.0
  • theming: 2.6.1
  • twofactor_backupcodes: 1.20.0
  • updatenotification: 1.21.0
  • user_status: 1.11.0
  • viewer: 4.0.0
  • webhook_listeners: 1.2.0
  • workflowengine: 2.13.0
    Disabled:
  • activity: 4.0.0 (installed 4.0.0)
  • admin_audit: 1.21.0
  • comments: 1.21.0 (installed 1.21.0)
  • contactsinteraction: 1.12.0 (installed 1.12.0)
  • dashboard: 7.11.0 (installed 7.11.0)
  • encryption: 2.19.0
  • files_external: 1.23.0
  • nextcloud_announcements: 3.0.0 (installed 3.0.0)
  • photos: 4.0.0-dev.1 (installed 4.0.0-dev.1)
  • recommendations: 4.0.0 (installed 4.0.0)
  • suspicious_login: 9.0.1
  • systemtags: 1.21.1 (installed 1.21.1)
  • text: 5.0.0 (installed 5.0.0)
  • twofactor_nextcloud_notification: 5.0.0
  • twofactor_totp: 13.0.0-dev.0
  • user_ldap: 1.22.0
  • weather_status: 1.11.0 (installed 1.11.0)

at least one topic exists Docker: how to use postfix from host

I frequently see connection issues with connections between containers on the same host. I assume there are issues with iptables but I never was in the mood to troubleshoot. as my relevant containers are all http behind reverse proxy I just made intern split-brain dns on the reverse proxy Probably DNS help with NC Docker + Collabora + Wireguard tunnel

Newer Docker versions include a special hostname host.docker.internal → add as --add-host=host.docker.internal:host-gateway argument

https://medium.com/@TimvanBaarsen/how-to-connect-to-the-docker-host-from-inside-a-docker-container-112b4c71bc66