Self-hosted Mailcow, relaying through MXRoute

I self-host my emails using Mailcow. Inbound emails come directly to my server, but outbound emails are routed through MXRoute because their deliverability is much better than mine.

Someone on LowEndTalk asked about this setup:

@tarasis said:

@Daniel15 said:

@the_doctor said: Do you have any tips to get the IP reputation up?

I cheated :rofl: I relay outbound emails through MXRoute.

I already had a good Black Friday package for MXRoute. I set up a catchall account for each domain in MXRoute, then on my server I use Mailcow and configured each domain to use the relevant account for relaying. Inbound mail comes directly to me, while outbound email goes via MXRoute. It works great.

I would have used MXRoute but I have some specific requirements. My email account has ~400k emails in it. I need to clean it up at some point, but I do search through them to find old emails sometimes. Search on an account that size is just impossible without something like Solr (which MXRoute doesn’t use). I used to have this account at MXRoute and tried their search but gave up after waiting a minute with no results.

Oh, can I message you about your setup? I used to self host, then switched to MXRoute but I’ve been having issues with increased spam and legit emails I signed up to not making it through despite whitelisting the domain.

So I was thinking about self hosting the receiving again, and using MXRoute for outbound.

so I figured I’d make a post of it, rather than just PMing them.

In Mailcow, set up your domains and mailboxes like normal. I assume you’ve already done this.

In MXRoute’s cPanel or DirectAdmin, create one account per domain.
Configure the account as a catchall for the domain. In cPanel, this is under Forwarders / Aliases → Add Domain Forwarder. Not sure where it is in DirectAdmin as I don’t have any DirectAdmin accounts to test with. The reason it needs to be a catchall is so it can be used to send mail from any address at the domain.

Set your MX record to your server (not MXRoute), and the SPF to both your server and MXRoute. Example SPF:

v=spf1 ip4:198.51.100.1 ip6:2001:db8::1 include:mxroute.com -all

where 198.51.100.1 and 2001:db8::1 are your server’s IPs. You can use mx instead of specifying the IPs, but that adds an extra DNS lookup, and SPF records fail if there’s too many DNS lookups required.

If you use DKIM/DomainKeys, configure it for both your server and MXRoute, using different selectors for each. Details about how to configure this are outside the scope of this post.

In Mailcow, go to Configuration (in the top menu) → Configuration & Details → Routing tab.

Under “Add sender-dependent transport”, add the login details for your account:

Once it’s added, click the “test” button next to it


Enter a from address at your domain, leave the to address as [email protected], and ensure it works (you get a 250 OK at the end):

Go to Configuration → Mail Setup → Domains, and click “Edit” next to the domain

In the “Sender-dependent transports” dropdown, select the correct relay for this domain:

Now send an email through webmail or your email client, and see if it works. :smile:

These instructions show Mailcow since that’s what I use, however it uses a standard Postfix feature called sender_dependent_relayhost_maps, so you can do the same thing through other systems like Mail-in-a-box or by directly modifying the Postfix config.

10 Likes

I do almost exactly the same thing. Love MXRoute deliverability, and love straight postfix receivability!

2 Likes

Mailcow is SoGO? Other than being self-hosted, what’s cool about Mailcow? :sunglasses:

SOGo is a component used by Mailcow. It handles webmail, ActiveSync (for real-time push on mobile apps that don’t support IMAP IDLE), and calendar syncing.

Everything works out-of-the-box. There’s other solutions too (like Mail-in-a-box), but I like Mailcow the most. Everything uses Docker which avoids making a mess of the host system.

1 Like