This question has a related answer here: How can I forward mail while saving a copy using postfix and mysql? But there are two problems with it:
- the OP's setup uses MySQL and all answers are geared towards that, and
- the answer that seems to be the one I want, the one that uses main.cf and hash tables, is from 2009 (and got no attention then). So I'd like to ask this one again, for a config file setup instead of a MySQL setup.
I'm forwarding mail to my gmail address successfully with these lines in /etc/postfix/main.cf:
virtual_alias_domains = example.com, example.net
virtual_alias_maps = hash:/etc/postfix/virtual
and in /etc/postfix/virtual:
@example.com myusername
@example.net myusername
myusername [email protected]
This works great and forwards all mail to [email protected], but I'd like to keep a copy on the server. Ideally they'd go to myusername's inbox. What's the proper way to do this?
My /var/log/mail.log log after sending a test email:
Oct 8 09:16:26 myservername postfix/qmgr[1494]: 89736105BA7: from=<[email protected]>, size=1676, nrcpt=2 (queue active)
Oct 8 09:16:26 myservername postfix/trivial-rewrite[7338]: warning: do not list domain mydomain.com in BOTH mydestination and virtual_alias_domains
Oct 8 09:16:26 myservername postfix/cleanup[7339]: B7888105BB0: message-id=<CAGS0grDYkvWj_wxpGKW1h7XJZ5YEky3DwPBnB4XdvE3TU-W7jg@mail.gmail.com>
Oct 8 09:16:26 myservername postfix/local[7340]: 89736105BA7: to=<[email protected]>, relay=local, delay=0.21, delays=0.19/0.01/0/0.01, dsn=2.0.0, status=sent (forwarded as B7888105BB0)
Oct 8 09:16:26 myservername postfix/qmgr[1494]: B7888105BB0: from=<[email protected]>, size=1802, nrcpt=1 (queue active)
Oct 8 09:16:26 myservername postfix/smtpd[7335]: disconnect from mail-io0-f171.google.com[209.85.223.171]
Oct 8 09:16:27 myservername postfix/smtp[7341]: connect to gmail-smtp-in.l.google.com[2607:f8b0:400e:c04::1a]:25: Network is unreachable
Oct 8 09:16:27 myservername postfix/smtp[7342]: connect to gmail-smtp-in.l.google.com[2607:f8b0:400e:c04::1a]:25: Network is unreachable
Oct 8 09:16:27 myservername postfix/smtp[7342]: B7888105BB0: to=<[email protected]>, orig_to=<[email protected]>, relay=gmail-smtp-in.l.google.com[74.125.28.26]:25, delay=0.89, delays=0/0.01/0.6/0.27, dsn=2.0.0, status=sent (250 2.0.0 OK 1444310187 n40si31732683ioi.161 - gsmtp)
Oct 8 09:16:27 myservername postfix/qmgr[1494]: B7888105BB0: removed