Honestly, i don't quite understand why you do it this way.
Maybe you can use mail forwarding or something like this to achieve the same goal. Make things easy/simple please if possible.
I am making a virtual machine group with multiple virtual machines (one machine for iRedmail) and I have configured all email clients in the vm-group to fetch mail from username@domain.com.
From the same email address? or username@[SUB_DOMAIN]?
I need to configure it so that mail sent to i.e. 4.domain.com goes to vm-group 4 and iredmail of the group4 will forward the mail to username@domain.com and only the clients from vm-group 4 will get the mail.
Do you send mail to a random username of 4.domain.com? not a hard-coded one? for example, 'root@4.domain.com'. Is it possible to configure it to sent to a hard-coded one?
If it's sent to 'root@4.domain.com' (root user), then you can update /etc/postfix/aliases on server 4.domain.com to forward all emails sent to root user to an email address.