2

I am trying to send all local mail to a single external e-mail, using Google's SMTP servers (I got that working following this nice tutorial).

Using Google's SMTP servers work, as I am able to send mail to external addresses work using mail from mailutils.

The redirection of local mail to the external e-mail does not work. When sending a mail to root from my account test using:

echo "Body" | mail -s "Test Postfix To Root" root
  • I never recieve the message
  • Nothing new turns up in /var/log/mail.err
  • This turns up in /var/log/mail.log
Sep  4 18:48:06 desktop1204test postfix/pickup[5535]: C9326EE26: uid=1000 from=
Sep  4 18:48:06 desktop1204test postfix/cleanup[5702]: C9326EE26: message-id=
Sep  4 18:48:06 desktop1204test postfix/qmgr[5534]: C9326EE26: from=, size=401, nrcpt=1 (queue active)
Sep  4 18:48:06 desktop1204test postfix/local[5704]: C9326EE26: to=, orig_to=, relay=local, delay=0.03, delays=0.02/0/0/0, dsn=2.0.0, status=sent (delivered to mailbox)
Sep  4 18:48:06 desktop1204test postfix/qmgr[5534]: C9326EE26: removed

My /etc/postfix/main.cf:

inet_interfaces = loopback-only
mynetworks = loopback-only
alias_maps = hash:/etc/aliases
alias_database = hash:/etc/aliases
## I commented the below two lines out, as they conflicted with the accepted answer
####virtual_alias_domains = localhost.localdomain
####virtual_alias_maps = hash:/etc/postfix/virtual
relayhost = [smtp.gmail.com]:587
smtp_sasl_auth_enable = yes
smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd
smtp_sasl_security_options = noanonymous
smtp_tls_CAfile = /etc/postfix/cacert.pem
smtp_use_tls = yes

My etc/aliases:

# See man 5 aliases for format
postmaster:    root

My /etc/postfix/virtual:

@localhost.localdomin        [email protected]

How can I get it working? I don't want any local mail to arrive locally, they should all go to [email protected].

0

2 Answers 2

2

This can be accomplished via virtual regexp (/etc/postfix/virtual-regexp)

/.+@.+/ [email protected]

then in main.cf:

virtual_maps = hash:/etc/postfix/virtual, regexp:/etc/postfix/virtual-regexp

and the mapfile:

postmap /etc/postfix/virtual-regexp

That should do the trick for all local mails (otherwise you must specify all addresses on virtual)

1
  • If I do that I get postconf: warning: /etc/postfix/main.cf: unused parameter: virtual_maps=hash:/etc/postfix/virtual, regexp:/etc/postfix/virtual-regexp (but I will see if I can fix it)
    – Deleted
    Sep 4, 2013 at 20:20
1

To those who want to send out mail to other domains normally (e.g. on a send-only null client), and have mail to system accounts delivered remotely, you create /etc/postfix/virtual-regexp. In it, either map all system accounts that don't have a real inbox to another:

/^\(root\|postmaster\|postfix|etc\)@domain\.example$/ [email protected]

or map all accounts that aren't known real inboxes (do not indent the if):

if /@domain\.example$/
!/^\(person\|anotherperson\|peeps\)@/ [email protected]
endif

This is a lot easier if your myorigin setting in /etc/postfix/main.cf is different to your real inbox domains (e.g. a subdomain of mail.domain.example) as then you can match everything like so:

/@mail\.domain\.example$/ [email protected]

As others said, do not run postmap on this file, and delete /etc/postfix/virtual-regexp.db if it exists.

Use the new mapping by adding

local_recipient_maps =
virtual_alias_maps = regexp:/etc/postfix/virtual-regexp

to /etc/postfix/main.cf.


I also added

root: [email protected]

to /etc/aliases and ran the newaliases command, but I think Postfix's virtual alias configuration overrides it.

You must log in to answer this question.

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