I have a postfix mail server running on a Debian machine.
This server handles all incoming mail. However, I want all mail sent to a certain subdomain to be handled by another mail server running on another port on the computer.
In other words, all mail going to *@subdomain.domain.tld should go to address and port XX.XX.XX.XX:YYYY
At the moment I handle aliases in /etc/postfix/virtual but I don't see how to enter this rule there.
I should also mention, that postfix is (probably) not equipped to receive any mail coming to the subdomain at the moment. Therefore it would be great if you could explain how to get there from the start...
How can this be achieved?
If I understand your question correctly, you have to (1) enable relay for this domain and (2) set the destination server in transport map.
Backup the postfix config file before any changes (not required, but recommended).
In order to allow relay, you need to set
relay_domains = subdomain.domain.tld in your postfix config (most likely /etc/postfix/main.cf).
Then, you need to set destination server in the config file for this domain using
transport_maps = hash:/etc/postfix/transport (or any other file postfix has access to); create this file with content
subdomain.domain.tld smtp:XX.XX.XX.XX:YYYY, (assign permissions if needed) and build the database using shell command
Don't forget to restart postfix after your changes.