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 firstname.lastname@example.org
This works great and forwards all mail to email@example.com, 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: 89736105BA7: from=<firstname.lastname@example.org>, size=1676, nrcpt=2 (queue active) Oct 8 09:16:26 myservername postfix/trivial-rewrite: warning: do not list domain mydomain.com in BOTH mydestination and virtual_alias_domains Oct 8 09:16:26 myservername postfix/cleanup: B7888105BB0: message-id=<CAGS0grDYkvWj_wxpGKW1h7XJZ5YEky3DwPBnB4XdvE3TU-W7jg@mail.gmail.com> Oct 8 09:16:26 myservername postfix/local: 89736105BA7: to=<email@example.com>, 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: B7888105BB0: from=<firstname.lastname@example.org>, size=1802, nrcpt=1 (queue active) Oct 8 09:16:26 myservername postfix/smtpd: disconnect from mail-io0-f171.google.com[188.8.131.52] Oct 8 09:16:27 myservername postfix/smtp: 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: 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: B7888105BB0: to=<email@example.com>, orig_to=<firstname.lastname@example.org>, relay=gmail-smtp-in.l.google.com[184.108.40.206]: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: B7888105BB0: removed