Score:0

Postfix forwarding to Gmail and local UNIX user

cn flag

I would like to forward all email coming to everything in @foo.com to [email protected] and also to the UNIX user baz.

I tried adding both baz and [email protected] to the virtual file (see config below), but it only seems to forward mails to [email protected] and not add it to /var/mail/baz. No errors regarding delivering to baz show up in the log either (nor does it even mention baz in the /var/log/mail.log; [email protected] does show up in the log though with a status=sent, after which qmgr says "removed"; no further information about the test email shows up).

Is there something that I am missing? man 5 virtual says @domain address, address, ... is accepted as a pattern, so I think this should just work, right?

/etc/postfix/main.cf:

smtpd_banner = $myhostname ESMTP $mail_name (Debian/GNU)
biff = no
append_dot_mydomain = no
readme_directory = no
compatibility_level = 2

# TLS parameters
smtpd_tls_cert_file=/etc/ssl/certs/ssl-cert-snakeoil.pem
smtpd_tls_key_file=/etc/ssl/private/ssl-cert-snakeoil.key
smtpd_use_tls=yes
smtpd_tls_session_cache_database = btree:${data_directory}/smtpd_scache
smtp_tls_session_cache_database = btree:${data_directory}/smtp_scache

smtpd_relay_restrictions = permit_mynetworks permit_sasl_authenticated defer_unauth_destination
myhostname = mailme
alias_maps = hash:/etc/aliases
alias_database = hash:/etc/aliases
myorigin = /etc/mailname
mydestination = $myhostname, mailme.foo.com, mailme, localhost.localdomain, localhost
relayhost =
mynetworks = 127.0.0.0/8 [::ffff:127.0.0.0]/104 [::1]/128
mailbox_size_limit = 0
recipient_delimiter = +
inet_interfaces = all
# Use only ipv4; for some reason ipv6 (used when set to "all") causes "network unreachable" messages in /var/log/mail.log
inet_protocols = ipv4

# Forwarding
virtual_alias_domains = foo.com
virtual_alias_maps = hash:/etc/postfix/virtual

/etc/postfix/virtual:

@foo.com        baz, [email protected]
Paul avatar
cn flag
What happens if you make an entry in `aliases`? I'm not clear why that won't work for you.
Jay Bosamiya avatar
cn flag
Thanks for the suggestion. I tested by adding `baz: /var/mail/baz` to `/etc/aliases` (and running `newaliases` and restarting postfix) but it still won't work.
Lexib0y avatar
cn flag
Did you run postmap on /etc/postfix/virtual ?
Score:0
us flag
dan

@foo.com within your /etc/postfix/virtual is a wildcard. ( extract from the comment within /etc/postfix/virtual ).

This means that everything destinated to [email protected] will be accepted if user is a local account or not.

Within your virtual file, baz isn't a correct address, it is a user account. A correct address would be baz@mydomain. And of course, mydomain couldn't be foo.com nor anything within a subdomain, unless you want to play with infinite rewriting loops.

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.