-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implement SRS for forwarded mail #2418
Comments
I am waiting for Rspamd to implement it. |
How much better is having it in Rspamd than using a simple postsrsd setup? (Rspamd is probably way more flexible with scripting but I wonder how necessary this is.) Also, I just realized that BCC maps too does forwarding, but unlike the other forwarding (redirect through sieve filter) the forwarded mail doesn't show up in Rspamd's history (the other did) and that bounce non-delivery notification doesn't get sent to the original sender. Postsrsd still does SRS rewrite with my test setup, but what if it's implemented in Rspamd but the forwarded mail doesn't go through it? |
This might help you out : rspamd/rspamd#1789 |
BCC maps are not meant to be used for forwarding at all btw. |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
So what's the gist of this thread? We'll wait for rspamd/rspamd#1789 to implement it? |
You can implement it to Rspamd or help Vsevo with it. There are also sieve redirects. |
I'd like to see this implemented too |
Same here @leifnel , seeing as rspamd/rspamd#1789 is closed and has the labels "bug" and "wontfix" it seems that rspamd won't be implementing this. Is there anyone that has an alternative way to achieve this? I've been unable to find the right instructions to get this sorted. |
I stumbled upon this issue now, since I have a few mail aliases to forward externally. I'm somehow surprised that mailcow is not able to do SRS. :/ Until then: Any ways to workaround this? |
@TiiFuchs so depending on how much around working you can put up with, SRS Milter might work for you. (If I remember correctly I picked this because it was relatively the most up-to-date and straightforward to setup and configure.) |
@PAStheLoD Do you have an example docker-compose.yml and maybe configuration files for SRS Milter so I have something to begin with? |
Sorry, no docker-compose. I'm using it with ISPConfig. So just a VM + Postfix + SRS Milter in Docker. There's not much to configure either. (I use the docker run command from the README. Except for the domain name it's identical. And simply modify postfix's main.cf, add the milter to the list of milters using the Does this help you get started? |
I configured it accordingly, but it does not seem to work. I don't get any output or errors either :/ |
It seems that srs-milter rewrites mails that gets delivered to a local mail account, but not if the mail gets redirected to another external mail account... I don't understand why...? |
It seems that it's not working with mails redirected via a configured alias in the mailcow admin. So I'm fairly confused now, tbh. |
I'm not familiar with the inner workings of mailcow, but if the milter setting is in the postfix config you can tcpdump the traffic between the milter and postfix.
So it's not needed because there's some component that implements a similar rewrite functionality via sieve? :o How? :0 |
As far as my tests go, the mails redirected via sieve filter sends it with headers as if it were sent from your mailcow mailbox. So SPF passes, since it checks if your mailserver is eligible for sending mails for YOUR domain, not that other freemail domain the original mail was from. I'm not that deep in the matter, so I don't know for sure what it is. I tested it from gmx.de -> my mailcow instance -> gmail, and gmail shows my mailbox in X-Sieve-Redirected-From, Delivered-To, To Headers. And it is listed in the ARC-Authentication-Results, Received and Authentication-Results Headers... |
Coming back to this, seeing how I already posted in 2019. Frustrating to be 4 years later and still have the same issue without a good solution. I found this blog-post here https://nowhere.dk/articles/implementing-srs-with-mailcow/ which dates from 2020 already, but it seems adapted to mailcow-dockerized, so I'll probably be giving this a go. Or alternatively try the same using I'm not entirely happy with the way srs is handled through that regex in the blogpost though. I can see how it simplifies things, but it would be much better if somehow we could pass the mail through EDIT: This original post (from 2017) contains an example where the recipient domains that need rewriting aren't based on the regex, but rather just look at the list of local domains using an SQL query. IMHO that is the correct way to go about this. Since then, All in all, I'm afraid this won't be a quick fix-up and likely turn into a week-end project. Our users will have to bear with the current situation for a little while longer. |
Seconded. SPF succeeds because the sieve filter redirect updates the Return-Path. Other mail forwarders do not do this and cause SPF to fail. |
The I just wanted to add a small thought I had about this earlier this week: I feel like, if At the very least a note on the alias form, informing people that this is not guaranteed to work if using external domains as targets would be a good thing to add, don't you agree? |
I think I have a set-up that works. At least my latest tests suggest it does. I'll write this up another time though, giving that it's already quite late and I haven't had dinner yet and I don't want to just dump my unsorted, raw notes on you. Maybe @andryyy can let us know what the initial idea was behind using |
DisclaimerThe original post here below is not correct and needs updating. In the meantime, please see my post below. Original PostOK, here goes nothing! Disclaimer: I am not a As I outlined before, I didn't want to go the In The first step is to add a container for version: '2.1'
services:
[…]
postsrsd-mailcow:
image: ajoergensen/postsrsd:latest
restart: always
environment:
- SRS_DOMAIN=mail.mymx.lu
- SRS_SECRET=************
networks:
mailcow-network:
ipv4_address: ${IPV4_NETWORK:-172.22.1}.42 You can generate the secret any way you want, e.g. All the files that I'll mention from here on can be found on your host system at We'll start by visiting In
First of all, we tell The second part is overriding the user = mailcow
password = **********
hosts = unix:/var/run/mysqld/mysqld.sock
dbname = mailcow
query = SELECT IF(EXISTS(SELECT domain FROM domain WHERE domain = '%d' UNION SELECT alias_domain FROM alias_domain WHERE alias_domain = '%d'), NULL, 'smtp:127.0.0.1:10029') AS 'transport' The query simply checks whether the recipient domain is a local domain. If a result is found ( And where we define that process is in
I left my comments in to illustrate two points that we'll get to in a moment. First, what we see here is that we're asking postfix to start two processes when it starts up. One The cleanup service is "cleaning up" headers. And the important bit here is the user = mailcow
password = ********************
hosts = unix:/var/run/mysqld/mysqld.sock
dbname = mailcow
query = SELECT '%s' FROM alias WHERE domain = '%d' We're basically just returning a local address if the domain exists locally. Meaning, we're rewriting the original sender address to itself. The reason why querying the In essence this is all that there is to it, but, on to my comments:
Mar 19 21:13:10 139f3df59ee5 postfix/proxymap[379]: warning: request for unapproved table: "mysql:/opt/postfix/conf/sql/mysql_local_senders.cf"
Mar 19 21:13:10 139f3df59ee5 postfix/proxymap[379]: warning: to approve this table for read-only access, list proxy:mysql:/opt/postfix/conf/sql/mysql_local_senders.cf in main.cf:proxy_read_maps
Mar 19 21:13:10 139f3df59ee5 postfix/cleanup[414]: fatal: proxymap service is not configured for table "mysql:/opt/postfix/conf/sql/mysql_local_senders.cf" This is easily solved by doing just that, adding it to the
However, after restarting the
ProblemsThe problems that remain are those of the risk of Feedback? / Questions?I'd love some feedback on this. E.g. on the Also, if you have questions about my approach, if something isn't clear, please let me know. Edit May 23rd 2023If you pulled a new container after May 21st 2023, the configuration needs to be changed to adapt to a new In a nutshell, these changes are required: extra.cf
master.cf
For more information, see these threads and @ajoergensen's original, updated blog post |
@kwisatz I love that! Thanks for all the effort! |
@andryyy did you have a chance to check my post above? Any ideas about the problems I mention, any feedback from your side? Also, who maintains the list of third party integrations here https://docs.mailcow.email/third_party/borgmatic/third_party-borgmatic/ and how? |
@kwisatz thanks for this great write up. It looks like this is SRS rewriting the local source address for any outgoing email which is sent from the local domain as well as anything external which is being forwarded by my Sieve filter. While this isn't preventing delivery, it feels like this is not really correct behaviour, so how can the configuration be updated accordingly do you think? Also, can this solution be combined with using a smarthost relay for the SRS domain I'm using? Configuring that domain in the Mailcow UI to use a sender-dependent transport doesn't seem to do the trick. |
It shouldn't be doing that. If it is, then we need to figure out what is wrong about the config.
with user = mailcow
password = ********************
hosts = unix:/var/run/mysqld/mysqld.sock
dbname = mailcow
query = SELECT '%s' FROM alias WHERE domain = '%d' This query inside @cjwalsh can you give an example of which addresses are being rewritten and how? Do your logs maybe show anything interesting about
So what you mean is that after an external domain has been rewritten, it should get routed (transported) towards the smarthost? With the current config that indeed won't work, because transports are queried before we even get to the SRS stuff:
I'm thinking you should be able to switch out both config files, making it look up the non-local srs config first. But this would also require that the |
@kwisatz I found the issue, the sender addresses were being rewritten by the default cleanup service, because I had added the For clarity, this is what the data/conf/postfix/extra.cf
Also for reference, here is the section from data/conf/postfix/master.cf
Once I got that resolved I then found that the Sieve filter for redirecting to my @gmail.com address wasn't using the SRS redirect, and it appears that this is because Dovecot in Mailcow seems to be configured in a non-default way for the This configuration can be changed, and it seems that the safest way to override the setting is by creating an data/conf/dovecot/extra.conf
For the smarthost relaying, I was wondering if the smtpd settings in By the way, I think it is already routing the messages back from the SRS |
What's the current status of this? Is SRS working with this additional service and configuration? Or is there still a conflict with rspamd? |
@pgassmann I'm not aware of any conflicts with |
I tested this with the current Mailcow version and I don't see any problem with rspamd etc. It just works. I will have a look at this for a longer time in our setup and report back. |
@cjwalsh I'm now seing a similar behavior to what you described, but I can't say that I fully understand what is going on: mailcowdockerized-postfix-mailcow-1 | Dec 5 15:53:56 ede301d27bd1 postfix/sogo/smtpd[458]: connect from mailcowdockerized-sogo-mailcow-1.mailcowdockerized_mailcow-network[172.22.1.248]
mailcowdockerized-postfix-mailcow-1 | Dec 5 15:53:56 ede301d27bd1 postfix/sogo/smtpd[458]: D18D030FB06: client=mailcowdockerized-sogo-mailcow-1.mailcowdockerized_mailcow-network[172.22.1.248], sasl_method=PLAIN, [email protected]
mailcowdockerized-postfix-mailcow-1 | Dec 5 15:53:56 ede301d27bd1 postfix/cleanup[459]: D18D030FB06: replace: header Received: from 56273ad8fbc2 (mailcowdockerized-sogo-mailcow-1.mailcowdockerized_mailcow-network [172.22.1.248])??(Authenticated sender: [email protected])??by mail.mx.tld (Postcow) with ESMTPA id D18D0 from mailcowdockerized-sogo-mailcow-1.mailcowdockerized_mailcow-network[172.22.1.248]; from=<[email protected]> to=<[email protected]> proto=ESMTP helo=<56273ad8fbc2>: Received: from [127.0.0.1] (localhost [127.0.0.1]) by localhost (Mailerdaemon) with ESMTPA id D18D030FB06??for <[email protected]>; Tue, 5 Dec 2023 15:53:56 +0100 (CET)
mailcowdockerized-postfix-mailcow-1 | Dec 5 15:53:56 ede301d27bd1 postfix/cleanup[459]: D18D030FB06: message-id=<5a-656f3980-7-62280700@210026301>
mailcowdockerized-postfix-mailcow-1 | Dec 5 15:53:57 ede301d27bd1 postfix/qmgr[383]: D18D030FB06: from=<[email protected]>, size=902, nrcpt=1 (queue active)
mailcowdockerized-postfix-mailcow-1 | Dec 5 15:53:57 ede301d27bd1 postfix/sogo/smtpd[458]: disconnect from mailcowdockerized-sogo-mailcow-1.mailcowdockerized_mailcow-network[172.22.1.248] ehlo=1 auth=1 mail=1 rcpt=1 data=1 quit=1 commands=6
mailcowdockerized-postfix-mailcow-1 | Dec 5 15:53:57 ede301d27bd1 smtpd-srs/smtpd[456]: connect from localhost[127.0.0.1]
mailcowdockerized-postfix-mailcow-1 | Dec 5 15:53:57 ede301d27bd1 smtpd-srs/smtpd[456]: 2AE2830FB13: client=localhost[127.0.0.1]
mailcowdockerized-postfix-mailcow-1 | Dec 5 15:53:57 ede301d27bd1 cleanup-srs/cleanup[457]: 2AE2830FB13: message-id=<5a-656f3980-7-62280700@210026301>
mailcowdockerized-postfix-mailcow-1 | Dec 5 15:53:57 ede301d27bd1 smtpd-srs/smtpd[456]: disconnect from localhost[127.0.0.1] ehlo=1 mail=1 rcpt=1 data=1 quit=1 commands=5
mailcowdockerized-postfix-mailcow-1 | Dec 5 15:53:57 ede301d27bd1 postfix/smtp[455]: D18D030FB06: to=<[email protected]>, relay=127.0.0.1[127.0.0.1]:10029, delay=0.46, delays=0.4/0.01/0/0.04, dsn=2.0.0, status=sent (250 2.0.0 Ok: queued as 2AE2830FB13)
mailcowdockerized-postfix-mailcow-1 | Dec 5 15:53:57 ede301d27bd1 postfix/qmgr[383]: 2AE2830FB13: from=<[email protected]>, size=1491, nrcpt=1 (queue active)
mailcowdockerized-postfix-mailcow-1 | Dec 5 15:53:57 ede301d27bd1 postfix/qmgr[383]: D18D030FB06: removed The BTW, you also mentioned that it won't hurt delivery, but it can. I just had such a case where we got a |
@cjwalsh ha, it only took me 2 years to finally understand the problem and come up with the same solution. It finally dawned on me what was wrong after I had solved an issue involving OpenDKIM on another mail server which sort of had the same origin. What finally made it click for me was the following FAQ from the postsrsd's README:
Which finally made me realize that the In a few words: The transport maps decide whether an email should go to the Note: Of course, the diagram above is super-simplified, see this page for an overview over how the different postfix services fit together… |
(Previously discussed in #110 and #1189)
Is your feature request related to a problem? Please describe.
Forwarded mail will fail SPF on receiving end.
Describe the solution you'd like
I would like to have SRS implemented for forwarded mail.
Additional context
I've used postsrsd in the past and it worked without issues. Though its README does mention that using
sender_canonical_maps
will cause the rewriting to happen even if the mail is not forwarded at all, which could be an issue to some other users.In order to test postsrsd again, I've set it up on a new testing mail server running mailcow-dockerized. I built and installed postsrsd on the host, changed its config with the correct mail domain and have it listen on
172.22.1.1
.main.cf
was changed like this (which I've probably done poorly):(I'll skip the wrestling with firewalld.)
I did some quick tests (setting forwarding via Roundcube to Gmail and checking the raw message there) and it seems to work fine. But this is a pretty hackish setup and I don't know if everything works (probably breaks apart when docker starts/stops).
(Btw I tried getting a bounce intentionally by forwarding to a non-existent user somewhere (with or without SRS) and the non-delivery notification ends up being sent to the original sender, which is probably very bad as it not only spams the original senders but also leaks the forwarding address. Perhaps this should be in a separate issue.)
The text was updated successfully, but these errors were encountered: