PMG – Relay based on recipient domain’s MX record (like in Mailcow)

May 8, 2025
14
2
3
Question: PMG – Relay based on recipient domain’s MX record (like in Mailcow)

Hi everyone,

I’m currently setting up Proxmox Mail Gateway (PMG) as a front-end mail filter and relay.
What I’m trying to achieve is a routing logic based on the MX record of the recipient domain, not just a static domain-to-host mapping.

Example use case:

Code:
Recipient Domain   | Public MX Record       | Desired Internal Relay Target
-------------------|------------------------|-------------------------------
domain1.de         | mx1.pmg-mail.de       | mail1.targetserver.de
domain2.de         | mx2.pmg-mail.de       | mail2.targetserver.de
domain3.de         | mx3.pmg-mail.de       | mail3.targetserver.de

So the idea is:

- PMG is listed as the public MX in DNS (e.g. `example.com MX 10 pmg.example.net`)
- When PMG receives the email, it should:
- Look up the MX record of the recipient domain (e.g. `mx1.pmg-mail.de `)
- Based on that MX, decide where to relay the message internally (e.g. to `mail1.targetserver.de`)

I’ve already implemented this in Mailcow, where it works well using `transport_maps`, e.g.:
Code:
domain1.de  mx: mx1.pmg-mail.de → relay: mail1.targetserver.de

The reason we want to do this dynamically is because we are hosting a large number of domains, and manually maintaining static transport rules for each one is not feasible.

We will synchronize the list of accepted/relayed domains into PMG via the API — unless there is a better or recommended way to manage that as well?

Is there any way to implement this kind of MX-dependent routing in PMG?
Or would we need to use an external script and the PMG API to regularly update transport rules based on the current MX values?

Is there any way to implement this kind of MX-dependent routing in PMG?
Or would I need to use an external script and the PMG API to regularly update transport rules based on the current MX values?

I’m aware that PMG allows static transport mappings per domain, but that’s not ideal in this case – I want the routing to be dynamic based on the DNS MX, without having to manage every domain manually.

Thanks in advance for any insights or ideas!
 
Not familiar with Mailcow. But PMG has standard transport_maps in "Mail proxy => Transports"
1747725073501.png

But you have to define MX record to search for. (in PMG you have to actively disable looking for MX if you want simple forwarding to specific host)
Same applies for default relay.

It just configures postfix - probably in same manner as mailcow you mentioned.
 
Last edited:
Hi,
Thanks for your response!


Mailcow automatically checks the MX record of a domain and can forward emails to the correct mail server using simple if-then logic.


For example:
MX mx1.domain.de → mailserver1.anotherdomain.de
MX mx2.domain.de → mailserver2.anotherdomain.de
MX mx3.domain.de → mailserver3.anotherdomain.de
...


This way, we don't have to manually create forwarding rules for each individual domain.
We simply use the API to tell Mailcow which domains are allowed to be relayed—everything else is handled automatically by looking up the MX records.
 
Hi,

I kinda do not understand what is the intended setup.

You do have registered public domains: domain1.de, domain2.de
You have one (can be more, but let's make it simple) PMG, known as pmg.domain1.de

What are MX records for those domains?
I was thinking it is:

doman1.de MX 10 pmg.domain1.de.
doman2.de MX 10 pmg.domain1.de.

When setup is like this, it is kinda impossible to use MX records of domain to do "dynamic" relaying because PMG would relay to itself (hence I cannot see that option in PMG because it does not make much sense)

Or is it something else? If it is so, how does incoming messages get to PMG?