Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

BCC forwarded e-mails

221 views
Skip to first unread message

Boban Davko

unread,
Oct 17, 2015, 12:08:38 PM10/17/15
to
Dear all,

Recently I have set up mail server using Postfix and Dovecot

Some of the accounts had to be bcc'ed to more than one account, and recipient_bcc_maps doesn't allow that

As an alternative, when email is received the server makes a bcc to <account id>@duplicator.localhost

When email is received for @duplicator.localhost, virtual_alias_maps forwards the email to all accounts specified for the current recipient's id (using mysql).

Irrelevant to the above, just fyi: there is one more rule in the virtual_alias_maps, that if receiver's domain is not duplicator.localhost, then checks whether the current account is of 'mailbox' or 'forwarding' type. First one means do nothing, because it should be bcc'ed to duplicator.localhost first, and the second one means that it will not be bcc'ed to @duplicator.localhost, but all specified addresses should be used to directly forward the received email to.

This is the configuration

recipient_bcc_maps = mysql:/etc/postfix/sqlconf/recipient_bcc_maps.cf
virtual_alias_maps = mysql:/etc/postfix/sqlconf/virtual_alias_maps.cf


 user            = vmail
 password        = xyz
 dbname          = mails
 query           = SELECT concat(u.id,'@duplicator.localhost') FROM users u WHERE u.username='%u' AND u.domain='%d' AND u.active='1' and u.type=0 /* 0=mailbox; 1=forwarding */ limit 1;
 hosts           = 127.0.0.1                    


 user            = vmail
 password        = xyz
 dbname          = mails
 query           =       SELECT n.address
                         FROM users u
                         LEFT JOIN next n ON n.id = u.id
                         WHERE ( u.active = '1' ) /* u.active = 1 means that the account is in use, otherwise it is disabled */
                               AND
                               (
                                 (
                                         '%d'      !=  'duplicator.localhost'
                                   AND   u.type     =  1
                                   AND   u.username =  '%u'
                                   AND   u.domain   =  '%d'
                                 )
                                 OR
                                 (
                                         '%d'       =  'duplicator.localhost'
                                   AND   u.id       =  '%u'
                                 )
                               );
 hosts           = 127.0.0.1

This setup works fine up to here with one exception I am trying to fix. When the email is forwarded by virtual_alias_maps to some (mailbox type) account, it is not bcc'ed further to @duplicator.localhost. Probably this happens because the email header of the forwarded email doesn't contain the current account as recipient.. Is there any way to rewrite the bcc field when forwarding an e-mail using virtual_alias_maps to include the current receiving account as recipient? I looked into recipient_canonical_maps, but it doesn't seem to allow bcc rewriting..

Best regards,
JC

Viktor Dukhovni

unread,
Oct 17, 2015, 12:58:12 PM10/17/15
to
On Sat, Oct 17, 2015 at 06:08:09PM +0200, Boban Davko wrote:

> Recently I have set up mail server using Postfix and Dovecot

> Some of the accounts had to be bcc'ed to more than one account, and
> recipient_bcc_maps doesn't allow that

Actually it does, indirectly. You can Bcc to an alias. Bcc
recipient addresses are subject to virtual(5) alias expansion.

> As an alternative, when email is received the server makes a bcc to
> <account id>@duplicator.localhost When email is received for
> @duplicator.localhost, virtual_alias_maps forwards the email to all accounts
> specified for the current recipient's id (using mysql).

Which appears to be what you're doing.

> This setup works fine up to here with one exception I am trying to fix.
> When the email is forwarded by virtual_alias_maps to some (mailbox type)
> account, it is not bcc'ed further to @duplicator.localhost. Probably this
> happens because the email header of the forwarded email doesn't contain
> the current account as recipient.. Is there any way to rewrite the bcc
> field when forwarding an e-mail using virtual_alias_maps to include the
> current receiving account as recipient? I looked into
> recipient_canonical_maps, but it doesn't seem to allow bcc rewriting..

The recipient_bcc_maps rewriting feature happens *before* virtual
alias expansion.

http://www.postfix.org/ADDRESS_REWRITING_README.html#receiving

Therefore, virtual alias expansion is NOT subject to BCC rewriting.
However, recipient bcc is in most ways just like virtual(5) aliases.
Either way mail is delivered to additional recipients. The only
difference is (to the extent possible) different bounce handling.

So your configuration would be a lot simpler if you switched entirely
from recipient_bcc_maps to virtual_alias_maps, and added all the
required additional recipients that way.

If you want to fancy it up, and emulate the bounce behaviour of
recipient_bcc_maps, you can defer the expansion of bcc recipients,
by not expanding them in virtual alias maps, but instead delivering
them via a custom transport where in addition to expansion of the
recipient, the envelope sender will be replaced. The below is
via a custom "local" transport, but you can also do interesting
things with custom pipe(8) transports, smtp proxies, ...

Warning: not tested!

virtual:
# Indexed file format, but SQL works just as well
us...@example.com us...@example.com, us...@bcc.invalid

transport:
bcc.invalid bcc

master.cf:
bcc unix - n n - - local
-o alias_maps=$bcc_alias_maps

main.cf:
indexed = ${default_database_type}:${config_directory}/
bcc_alias_maps = ${indexed}bcc

bcc:
# Indexed file example, but SQL works just as well
# Key feature, "owner-" aliases replace the envelope
# sender. Assumption, "example.com" is not a "local"
# domain. Otherwise deliver via SMTP into a separate
# Postfix instance, in which "bcc.invalid" is the only
# local domain in mydestination.
#
owner-user1: bcc-...@example.com
user1: bc...@example.com, bc...@example.com, ...

owner-user2: bcc-...@example.com
user2: bc...@example.com, bc...@example.com, ...

...

--
Viktor.

@lbutlr

unread,
Oct 17, 2015, 11:05:06 PM10/17/15
to
On Oct 17, 2015, at 10:08 AM, Boban Davko <gfin...@hotmail.com> wrote:
> Some of the accounts had to be bcc'ed to more than one account, and recipient_bcc_maps doesn't allow that

This is what I have (from memory, I can’t login to my mail server via ssh right now):

bcc_map:

Sa...@domain.tld sale...@domain.tld

And then in virtual:

sale...@domain.tld gru...@domain.tld, gru...@domain.tld, gru...@domain.tld, gru...@domain.tld, sal...@domain.tld

sale...@domain.tld b...@dimaint.tld, al...@domain.tld

--
"I program Windows - of course it isn't safe." - Meski

0 new messages