1

Context: let's say I have the domain example.com, but the registrar doesn't provide an "email forward" system.

How can I configure postfix (or even a simple Python script would be better, because I could customize certain forwarding rules) to use my server of IP 1.2.3.4 as a server that only redirects every mail incoming to *@example.com ("catch-all") to [email protected] ?

The DNS record would probably be something like:

mx.example.com                   MX     mailforwarder.example.com
mailforwarder.example.com        A      1.2.3.4
3
  • MX record is not IP but DNS name. Anyway you don't need MX, there's fallback to A record of the domain itself. I won't go with `sendmail', it's too big piece of mail server software for managing just one own domain. Check online with mxtoolbox.com. If you want something super easy, check opensmtpd.org, a mail server from OpenBSD OS which is super easy to setup.
    – Jiri B
    Commented Mar 22, 2021 at 9:49
  • Thanks @JiriB! It would be wonderufl if you can post an answer with a few steps about how to do this (*@example.com => redirected to [email protected]) with OpenSMTPD (I use Debian).
    – Basj
    Commented Mar 22, 2021 at 10:08
  • There is one caveat: GMail verifies SPF records. If you forward mails, you will encounter domains that have SPF records set. If you just forward the mails without rewriting the from-address, GMail will reject those mails. You can however install a simple mailbox system (e.g. some pop3 daemon) running on your server 1.2.3.4 and configure gmail to collect those mails: support.google.com/mail/answer/… - if that solution is OK for you, I can post an answer with detailed instructions.
    – Marcel Noe
    Commented Sep 14, 2021 at 9:24

1 Answer 1

4
+75

Just setup MX in DNS properly (without the useless clutter) and verify with:

dig example.com mx

Then this can be set up with postfix:

A) Create file /etc/postfix/virtual:

@example.com [email protected]

Alternatively, one can also forward per mailbox:

[email protected] [email protected]

B) Then create the alias mapping with:

postmap /etc/postfix/virtual

C) Then in file /etc/postfix/main.cf, the alias mapping needs to be referrenced:

virtual_alias_domains = example.com test.com
virtual_alias_maps = hash:/etc/postfix/virtual

D) Then reload the server with:

systemctl reload postfix
4
  • dig example.com mx does not set up a MX record, it displays it if it exists. Maybe you forgot to paste in the example output?
    – telcoM
    Commented Sep 12, 2021 at 23:26
  • It is good to verify the MX record/s on a terminal. Or just use online DNS/MX tools to validate, if you should not feel confident with that. And I mean, when reading the title of the question, it doesn't make the least sense, simply because this isn't the purpose of a MX (mail exchanger) record in the DNS. And when having several MX records (usually there are at least two of them, for minimum redundancy), these forwards would need to be configured on each destination host. Commented Sep 13, 2021 at 4:17
  • If it would be possible, that it could work as you'd imagine it to work... this would be highly insecure, because one could siphon emails by simple DNS poisoning - and alike I've explained, the mail needs to be delivered first (the DNS should also have DKIM & SPF records, so that the identify of the MX can be verified), before they're being forwarded. Hope this explains it better. Commented Sep 13, 2021 at 4:25
  • One can also load letsencrypt.org SSL certificates into postfix, simply because MX, DKIM, SPF (in DNS) and SSL encryption are quite the default configuration for a mail-server these days. And while you don't provide the zone file, I probably won't explain DNS to you, because it's a complex topic where one easily could write a book about it. Commented Sep 13, 2021 at 5:09

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .