I’ve installed Nextcloud using the official docker image.
Now I want to use the postfix from the host to relay the mails from the docker container. I’ve used this guide to change configuration to expose postfix to the Docker network, but so far I haven’t been able to send mails from Nextcloud (fyi: It is working on the host).
inet_interfaces = the IP address of docker0 interface using command ifconfig mynetworks = 192.168.32.0/20 : the subnet used by my Nextcloud docker container
Here are the mail settings in config.php from Nextcloud:
it doesn’t work this way -p 25:25 maps port 25 of the container to the port 25 of the host - which obviously doesn’t work as it is used already (most likely your container doesn’t start with such setting)
localhost and private IP/fqdn of the container are the same (settings are applied to the the container, so all IPs and hostnames are from the container point of view). the right setting would be IP/fqdn of the host. According to the tutorial you referenced:
Instead of providing the known SMTP server’s IP and host, one should use the IP of docker0, as explained above. In the case of many nodes in Kubernetes cluster with different docker0 IP, the Docker container of Jenkins master should reside only on one host and docker0’s IP on that host should be used.
you need to your 172.x.x.x address of the docker0 interface (previously configure postfix to listen on this interface as well) - see "Modified “/etc/postfix/main.cf” in your tutorial
inet_interfaces = localhost, 172.22.91.1
I remember there are restrictions in place when docker container talks to the host but don’t have any reference now… try searching for "docker container access host ip"or similar…
Indeed, I totally overlooked this. Oddly, I tried it before and my container did start without any warning that the port was already in use.
After some testing using nmap in the container I figured out I could use the IP address of docker0 to send mail (Note: you can also use the private IP of the host but for this you first need to add this IP to the inet_interfaces in main.cf - but it doesn’t make any difference)
Anyway I can now send test mails from my Nextcloud instance.
However: when sharing a file or adding a note I got the following error in mail.log:
(FYI: 172.24.0.3 is the IP of the nextcloud container)
This is very similar to the error I got last year using the same mail provider (yahoo) but using SMTP directly to yahoo.
It does seems strange to my as an 550 error means that the mailbox of the recipient does not exist, but this is not the case here obviously. How can I solve this, or should I create a separate post for this?
I have no idea about postfix but the following log
looks for me like you postfix accepted the message and forwarded it to yahoo, which in turn rejected the message (most likely to avoid open relay). I assume your postfix tried to send the message to yahoo without authentication…
According to this post - yahoo doesn’t like certain Reply To headers.
I’ve compared my mail headers, see below:
Test mail (=OK)
Received: from mycloud.com (unknown [172.24.0.3])
by myserver.oraclevcn.com (Postfix) with ESMTP id 008BAFD996
for <nextcloudadmin@gmail.com>; Fri, 8 Apr 2022 16:19:29 +0200 (CEST)
Message-ID: <46a2ffd86aa4b51d6466488bc3e7f1d6@mycloud.com>
Subject: Mail test
From: My Cloud <my.cloud@yahoo.com>
To: admin <nextcloudadmin@gmail.com>
MIME-Version: 1.0
Content-Type: multipart/alternative;
boundary="_=_swift_1649427569_1118be7e5e0306759d8028d78f8e50b2_=_"
X-SMTP-MAILFROM: my.cloud@yahoo.com
X-SMTP-RCPTTO: nextcloudadmin@gmail.com
References: <46a2ffd86aa4b51d6466488bc3e7f1d6.ref@mycloud.com>
X-Mailer: WebService/1.1.20001 mail.backend.jedi.jws.acl:role.jedi.acl.token.atz.jws.hermes.yahoo
Content-Length: 15170
Share by mail (bounced with 550 error)
Return-Path: <my.cloud@yahoo.com>
Received: from mycloud.com (unknown [172.24.0.3])
by myserver.oraclevcn.com (Postfix) with ESMTP id 24BACFD9B4
for <user@gmail.com>; Fri, 8 Apr 2022 15:47:28 +0200 (CEST)
Message-ID: <32ced750fc384e5a246175adf17184dc@mycloud.com>
Date: Fri, 08 Apr 2022 13:47:28 +0000
Subject: "admin" voegde een notitie toe aan een bestand dat met jou is
gedeeld
From: admin via My Cloud <my.cloud@yahoo.com>
Reply-To: admin <nextcloudadmin@gmail.com>
To: admin@gmail.com
MIME-Version: 1.0
Content-Type: multipart/alternative;
boundary="_=_swift_1649425648_db2e47324bf516359e593dd241515197_=_"
In the failed mail I do see a Reply-To mailadres which is different than the mail that the mail is send from. Maybe this causes the 550 mailbox unavailable error?
If so, this could be possibly solved by adding a fixed Reply-To header with the nextcloud mailadres (in my example my.cloud@yahoo.com)?
(I don’t know whether this is possible but I assume it is)
Edit:
I’ve checked with my other Nextcloud instance which is installed natively and also uses postfix.
When sending a mail by share by mail I notice that the Reply-To is indeed the mailadres used by Nextcloud to send the mails (instead of the mailadres of the user sharing the file. Thus guess the solution is indeed to somehow change the Reply-To headers?
Date: Fri, 08 Apr 2022 18:26:57 +0000
Subject: share by mail
From: user via Other-Cloud <other.cloud@yahoo.com>
Reply-To: user <other.cloud@yahoo.com>
To: otheruser@hotmail.com
MIME-Version: 1.0
Content-Type: multipart/alternative;
boundary="_=_swift_1649442417_0990c404215067f6fb0cde319f5552bb_=_"
References: <0de5c8a424b825165d7ef13378e1ba40.ref@wouter.servebeer.com>
X-Mailer: WebService/1.1.20001 mail.backend.jedi.jws.acl:role.jedi.acl.token.atz.jws.hermes.yahoo
Content-Length: 19904
Edit 2:
Seems that I was right. I used this to replace my Reply-To headers in my mail with the Nextcloud-mail address & now I don’t receive any 550 error anymore but 250 OK
Only downside is that the mails are delivered to the spam box from the recipient, but guess this is due to the nature of the automatically send mail.
I’ll send another post with the full solution of my 2 problems, guess it can help others who are using free mail services.
inet_interfaces = add the IP address of your docker0 interface e.g. 172.17.0.1
(user ip addr show of ifconfig and note the IP address corresponding to docker0, you don’t need to enter the mask e.g. /16)
Then restart your postfix service (e.g. sudo service postfix restart). If you have a firewall like ufw or iptables active, make sure you add rules to accept connections from your Nextcloud container IP to port 25.
Now you can add add the following to your Nextcloud config.php: