Skip to content

feat: Add list of allowed recipient domains#130

Open
dosmanak wants to merge 3 commits intojuanluisbaptiste:masterfrom
dosmanak:transport_map
Open

feat: Add list of allowed recipient domains#130
dosmanak wants to merge 3 commits intojuanluisbaptiste:masterfrom
dosmanak:transport_map

Conversation

@dosmanak
Copy link

@dosmanak dosmanak commented Nov 6, 2025

discard all email for not listed domains

Description of the change

Regarding an issue #90 but not exactly. This Feature enables to setup nonprod smtp-relay that allows to send e-mails only to allowed domains.
Other e-mails are silently discarded.

Motivation and Context

Tested application allows to send any e-mail without error but only particular recipient domains get through.

How Has This Been Tested?

podman run --rm -p 2525:25 -e SMTP_SERVER=smtp.sendgrid.net -e SMTP_USERNAME=apikey -e SMTP_PASSWORD=xxxxx -e SERVER_HOSTNAME=company.tld -e ALLOW_DOMAINS=gmail.com docker-postfix:transport_map

swaks --to studenyp@gmail.com --from test@company.tld --server localhost:2525

Types of Changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation (adding or updating documentation)

Checklist:

  • My change requires a change to the documentation and I have updated the documentation accordingly.
  • My change adds a new configuration variable and I have updated the .env.example file accordingly.

And lastly, many thanks for taking your time to help us improve this project !

@juanluisbaptiste
Copy link
Owner

Hi @dosmanak, thanks for your PR.

Code LGTM, will test it and let you know.

@juanluisbaptiste
Copy link
Owner

After various container restarts, the allowed domains are being duplicated in the /etc/postfix/transport file:

e4a07a47e63f:/# grep gmail /etc/postfix/transport 
gmail.com :
gmail.com :
gmail.com :

And the container logs:

postfix-1  | Nov 10 22:06:23 correo postfix/master[1]: daemon started -- version 3.10.5, configuration /etc/postfix
postfix-1  | Nov 10 22:06:46 correo postfix/smtpd[96]: connect from unknown[172.23.0.1]
postfix-1  | Nov 10 22:06:46 correo postfix/trivial-rewrite[98]: error: /etc/postfix/transport, line 320: duplicate entry: "gmail.com"
postfix-1  | Nov 10 22:06:46 correo postfix/trivial-rewrite[98]: warning: texthash:/etc/postfix/transport is unavailable. /etc/postfix/transport, line 320: duplicate entry: "gmail.com"
postfix-1  | Nov 10 22:06:46 correo postfix/trivial-rewrite[98]: warning: texthash:/etc/postfix/transport lookup error for "*"
postfix-1  | Nov 10 22:06:46 correo postfix/trivial-rewrite[98]: warning: texthash:/etc/postfix/transport is unavailable. /etc/postfix/transport, line 320: duplicate entry: "gmail.com"
postfix-1  | Nov 10 22:06:46 correo postfix/trivial-rewrite[98]: warning: texthash:/etc/postfix/transport lookup error for "*"
postfix-1  | Nov 10 22:06:46 correo postfix/trivial-rewrite[98]: warning: texthash:/etc/postfix/transport is unavailable. /etc/postfix/transport, line 320: duplicate entry: "gmail.com"
postfix-1  | Nov 10 22:06:46 correo postfix/trivial-rewrite[98]: warning: texthash:/etc/postfix/transport lookup error for "juan@juanbaptiste.tech"
postfix-1  | Nov 10 22:06:46 correo postfix/trivial-rewrite[98]: warning: transport_maps lookup failure
postfix-1  | Nov 10 22:06:46 correo postfix/trivial-rewrite[98]: warning: texthash:/etc/postfix/transport is unavailable. /etc/postfix/transport, line 320: duplicate entry: "gmail.com"
postfix-1  | Nov 10 22:06:46 correo postfix/trivial-rewrite[98]: warning: texthash:/etc/postfix/transport lookup error for "user@xxxxx.tld"
postfix-1  | Nov 10 22:06:46 correo postfix/trivial-rewrite[98]: warning: transport_maps lookup failure
postfix-1  | Nov 10 22:06:46 correo postfix/smtpd[96]: NOQUEUE: reject: RCPT from unknown[172.23.0.1]: 451 4.3.0 <user@xxxxx.tld>: Temporary lookup failure; from=<juan@xxxxx2.tld> to=<user@xxxxx.tld> proto=ESMTP helo=<mylaptop>
postfix-1  | Nov 10 22:06:46 correo postfix/smtpd[96]: disconnect from unknown[172.23.0.1] ehlo=1 mail=1 rcpt=0/1 quit=1 commands=3/4

@dosmanak
Copy link
Author

I have not assumed the scenario where the container restarts as I always delete it. Will look into it.

@juanluisbaptiste
Copy link
Owner

When the container is restarted, for example because the docker daemon was restarted because of an upgrade, or a server restart, in such cases the containers will not be recreated and this will happen.

@dosmanak
Copy link
Author

I added simple truncate of the file prior addind allowed domain and discard default. The solution is not very extendable but for now I think it will serve its purpose.

@juanluisbaptiste
Copy link
Owner

I think it would be cleaner if you look for the string you are adding first, instead of blindly adding it and truncate it before doing that. What if another feature in the future also touches that file?

@juanluisbaptiste
Copy link
Owner

@dosmanak did you have some time to update this PR?

@dosmanak
Copy link
Author

dosmanak commented Jan 7, 2026

I think it would be cleaner if you look for the string you are adding first, instead of blindly adding it and truncate it before doing that. What if another feature in the future also touches that file?

Well I did not planned it to be super strong. But I will look into that.

discard all email for not listed domains
keep the file frech after container restart
add function 'set_line_in_file' to check if line is not present before adding
@dosmanak
Copy link
Author

dosmanak commented Jan 7, 2026

What about this? Still not great, as it does not concerns line orders...

juanluisbaptiste added a commit that referenced this pull request Feb 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants