I’m going to reply even though it is already an old question. I feel documenting this when services like “Gmailify” will be ending, would not be a bad thing. Some might have used that and want to Degoogle a bit.
The current “Sender-dependent transports”, can only do it for an entire mailcow mailbox and not based of “From”.
“Transport Maps” is only meant for routing mail a specific way to specific receivers. Neither are looking at the “From”-header.
So the UI is unable to do this, so manual editing of configuration must be performed. Also I would recommend keeping sender checks enabled and simply using the “External sender addresses” setting of a mailbox to add the external email account to a mailcow mailbox.
In the following example I will be sending only as “your@external.email” using the external email server “smtp.external.email”.
The first step is to add the email to the “External sender addresses” list of the mailcow mailbox that should be allowed to send emails using this external email account. Use the mailcow gui to do that.
In data/conf/postfix/ edit or create the file “extra.cf” and add:
sender_dependent_default_transport_maps = pcre:/opt/postfix/conf/relay_by_sender
In data/conf/postfix/ create the file “relay_by_sender” with the contents:
/^your@external\.email$/ smtp.external.email
Once you have editted the file “relay_by_sender”, the following command should be ran:
docker compose exec postfix-mailcow postmap /opt/postfix/conf/relay_by_sender
After all these changes, restart the postfix-mailcow container and it should all be working! This is the basics to make postfix relay the email using “smtp.external.email” when the email is send from the email address “your@external.email”. If you do not need to authenticate to that external email server, you are done. If you need authentication, continue on.
You might notice mails send from that address will not be received/send, because “smtp.external.email” does probably require authentication. To add authentication some additional steps are required.
In data/conf/postfix/ edit the file “extra.cf” and add below:
smtp_sasl_password_maps = hash:/opt/postfix/conf/sasl_passwd proxy:mysql:/opt/postfix/conf/sql/mysql_sasl_passwd_maps_sender_dependent.cf
Doing this allows us to add more sasl records using “sasl_passwd” for our sender dependent relaying.
In data/conf/postfix/ create the file “relay_by_sender” with the contents:
# destination credentials
# per-sender authentication
your@external.email your_username@for_external.email:yourpassword
After creating this file the following command must be performed:
docker compose exec postfix-mailcow postmap /opt/postfix/conf/sasl_passwd
After all these changes, restart the postfix-mailcow container and it should all be working! I really wish this would get a lovely little UI in mailcow in the future, but until then this is the only way I believe that can be done.