3

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:

  1. the OP's setup uses MySQL and all answers are geared towards that, and
  2. 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 me@gmail.com

This works great and forwards all mail to me@gmail.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[1494]: 89736105BA7: from=<sending_address@gmail.com>, 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=<myusername@mydomain.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[1494]: B7888105BB0: from=<sending_address@gmail.com>, 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=<mygmailaddr@gmail.com>, orig_to=<myusername@mydomain.com>, 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
2

Just modify the last line

myusername me@gmail.com

so it becomes

myusername myusername me@gmail.com

Explanation

When postfix discover that an address was aliased to himself, then mail will be delivered to corresponding user instead

  • That doesn't seem to have worked, although it didn't break anything. I did do postmap /etc/postfix/virtual and postfix reload after, and when that didn't work, restarted postfix. – felwithe Sep 9 '15 at 0:32
  • Can you share full mail.log entry when you send email? Please post it by editing your question. – masegaloeh Sep 9 '15 at 0:34
  • updated with log – felwithe Oct 8 '15 at 13:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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