I have a server that is meant to deliver emails from PHP but not receive any emails. My domain MX records point to a different mail service and I have Postfix configured to not handle any FQDN emails. I'd like to send any local emails (postmaster errors, cronjob notices, etc.) to a single external email address me@external.com.

I've found a couple different questions on here that attempt to solve this (here and here most notably), but they seem to redirect all outbound emails as well, for example someone@gmail.com and someone@yahoo.com get delivered to me@external.com too.

One solution that does seem to work would be writing out virtual aliases for @localhost, @localhost.localdomain, and @cookweb1 separately to me@external.com, but surely there's a more elegant, generic solution? Here is the relevant part of my /etc/postfix/main.cf (erroneously forwards ALL mail to me@external.com):

myhostname = cookweb1
alias_maps = hash:/etc/aliases
alias_database = hash:/etc/aliases
myorigin = /etc/mailname
mydestination = cookweb1, localhost.localdomain, localhost
relayhost =
mynetworks = loopback-only
mailbox_size_limit = 0
recipient_delimiter = +
inet_interfaces = loopback-only
virtual_maps = hash:/etc/postfix/virtual, regexp:/etc/postfix/virtual-regexp

/etc/postfix/virtual is empty. Here is /etc/postfix/virtual-regexp (both have postmaps generated):

/.+@.+/ me@external.com
up vote 1 down vote accepted

When you said locally delivered email, I assume that you mean email delivered to domain @localhost, @localhost.localdomain, and @cookweb1. Because you have listed all of those domains in mydestination parameter, then you have to set catchall in alias_maps instead in virtual.

main.cf

alias_maps = regexp:/etc/postfix/local-catch
virtual_maps =

File /etc/postfix/local-catch

/.+/ me@external.com

Note: virtual_maps was deprecated and replaced by virtual_alias_domains and virtual_alias_maps.

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.