SMTP Confirmation email works. All other email's fail

I’m running the default/latest image of Nextcloud in docker, behind an nginx proxy.
Everything runs like a top, except for email.

My SMTP server is a mail-in-a-box server hosted on seperate public network.
In Basic Settings → Email Server, I entered my SMTP server settings (Used the domain name for the server address), click the “send email” button to test the settings, and I get an email from the system’s given email account. - Everything looks good.

However the system does not sent out new user emails or link share emails.
I checked the log and it looks like it’s trying to use 127.0.0.1 for the SMTP server address.

{"reqId":"6J7uYswC2ZfdDVwLBZIy","level":3,"time":"2022-01-12T02:50:17+00:00","remoteAddr":"172.21.0.2","user":"redacted","app":"ocs_api","method":"POST","url":"/ocs/v2.php/cloud/users","message":"Unable to send the invitation mail to user@redacted.com","userAgent":"Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/97.0.4692.71 Safari/537.36","version":"23.0.0.10","exception":{"Exception":"Swift_TransportException","Message":"Connection could not be established with host 127.0.0.1 :stream_socket_client(): Unable to connect to 127.0.0.1:25 (Connection refused)","Code":0,"Trace":[{"function":"{closure}","class":"Swift_Transport_StreamBuffer","type":"->","args":["*** sensitive parameters replaced ***"]},{"file":"/var/www/html/3rdparty/swiftmailer/swiftmailer/lib/classes/Swift/Transport/StreamBuffer.php","line":264,"function":"stream_socket_client","args":["127.0.0.1:25",0,"",10,4,null]},{"file":"/var/www/html/3rdparty/swiftmailer/swiftmailer/lib/classes/Swift/Transport/StreamBuffer.php","line":58,"function":"establishSocketConnection","class":"Swift_Transport_StreamBuffer","type":"->","args":[]},{"file":"/var/www/html/3rdparty/swiftmailer/swiftmailer/lib/classes/Swift/Transport/AbstractSmtpTransport.php","line":143,"function":"initialize","class":"Swift_Transport_StreamBuffer","type":"->","args":[{"protocol":"","host":"127.0.0.1","port":25,"timeout":10,"blocking":1,"0":"And 3 more entries, set log level to debug to see all entries"}]},{"file":"/var/www/html/3rdparty/swiftmailer/swiftmailer/lib/classes/Swift/Mailer.php","line":65,"function":"start","class":"Swift_Transport_AbstractSmtpTransport","type":"->","args":[]},{"file":"/var/www/html/lib/private/Mail/Mailer.php","line":204,"function":"send","class":"Swift_Mailer","type":"->","args":[{"__class__":"Swift_Message"},"*** sensitive parameter replaced ***"]},{"file":"/var/www/html/apps/settings/lib/Mailer/NewUserMailHelper.php","line":184,"function":"send","class":"OC\\Mail\\Mailer","type":"->","args":[{"__class__":"OC\\Mail\\Message"}]},{"file":"/var/www/html/apps/provisioning_api/lib/Controller/UsersController.php","line":446,"function":"sendMail","class":"OCA\\Settings\\Mailer\\NewUserMailHelper","type":"->","args":[{"__class__":"OC\\User\\User"},{"__class__":"OC\\Mail\\EMailTemplate"}]},{"file":"/var/www/html/lib/private/AppFramework/Http/Dispatcher.php","line":217,"function":"addUser","class":"OCA\\Provisioning_API\\Controller\\UsersController","type":"->","args":["*** sensitive parameters replaced ***"]},{"file":"/var/www/html/lib/private/AppFramework/Http/Dispatcher.php","line":126,"function":"executeController","class":"OC\\AppFramework\\Http\\Dispatcher","type":"->","args":[{"__class__":"OCA\\Provisioning_API\\Controller\\UsersController"},"addUser"]},{"file":"/var/www/html/lib/private/AppFramework/App.php","line":157,"function":"dispatch","class":"OC\\AppFramework\\Http\\Dispatcher","type":"->","args":[{"__class__":"OCA\\Provisioning_API\\Controller\\UsersController"},"addUser"]},{"file":"/var/www/html/lib/private/Route/Router.php","line":302,"function":"main","class":"OC\\AppFramework\\App","type":"::","args":["OCA\\Provisioning_API\\Controller\\UsersController","addUser",{"__class__":"OC\\AppFramework\\DependencyInjection\\DIContainer"},{"_route":"ocs.provisioning_api.Users.addUser"}]},{"file":"/var/www/html/ocs/v1.php","line":62,"function":"match","class":"OC\\Route\\Router","type":"->","args":["/ocsapp/cloud/users"]},{"file":"/var/www/html/ocs/v2.php","line":23,"args":["/var/www/html/ocs/v1.php"],"function":"require_once"}],"File":"/var/www/html/3rdparty/swiftmailer/swiftmailer/lib/classes/Swift/Transport/StreamBuffer.php","Line":261,"CustomMessage":"Unable to send the invitation mail to user@redacted.com"}}

Any Ideas where to look?

And what should be used? Same domain usually localhost.

I meant domain as opposed to IP addesss, as I’ve found several threads where they used that. Technically subdomain as the mail server has it’s own. As I stated in the post “hosted on seperate public network.”

I don’t get what you mean? Why should it use localhost for the SMTP server address when the SMTP server is hosted elsewhere? (Sorry, I’m really tired, it’s probably obvious) You mean that’s just the address for the local sendmail in the logs?

Ok, I still don’t get why the mail check delivers a test email perfectly, but the user creation and sharing flash up a popup error that it couldn’t be sent.

Could you than post your configuration? Where did you set “same domain”?
E.g. my config for gmail relay you can find here:

Here’s my setup:
smtp

Here’s the confirmation email I recieved:

Hi @davev

Does this system@home.yourdomain.com address, respective the “home” subdomain exist on the Mail-In-A-Box server? Afaik the “From address” should be the same as the one you send the mails with and login to the SMTP server of your MiaB, which means it has to exist on your mail server. I use a MiaB myself and I created dedicacted accounts on it for each of my servers. I normaly use hostname@mydomain.tld. In your case you could use home@yourdomain.com or system.home@yourdomain.com.

Example:

Create a new user on your MiaB called e.g.: system.home and then use the following settings in Nextcloud

Send Mode: SMTP
Encryption: SSL/TLS
From address: home.system@yourdomain.com
Sever address: mail.yourdomain.com:465
Authentifiaction method: “Login” with “Authentification required”
SMTP Username: home.system@yourdomain.com

Yup. It’s in there because I’m using MIAB’s CURL DNS Updates for this domain. This box has it’s own subdomain and one email user names “system.”

Email works, I’m convinced it a config problem somewhere other than normal.

I noticed that in the volume, there is a swift.config.php inside the config directory that is blank.
Does that need to have something set in it?

Hmm, sorry then I don’t know what causes the issue. I don’t have that file on my Nextcloud installation. The Email settings are stored in the normal config.php file.

My email settings are in the config.php file too.
I’m brand new to docker. Watched several hrs of tutorials on youtube…
The fact that you say you don’t have that file makes me wonder if I really don’t have the official nextcloud image.

In my docker-compose.yml I have
nextcloud-app:
image: nextcloud
restart: always

Which I assumed downloaded from the main official image.
Maybe I’m mixed up about that and have a another image?

I use a manual installation in an Ubuntu 20.04 VM. Can’t really help with Docker specific issues. But yes, image: nextcloud should pull the official one…

https://hub.docker.com/_/nextcloud