Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Email Aliases in Drop Down for BCC Maps under Address Rewriting #3713

Open
soulsymphonies opened this issue Aug 18, 2020 · 18 comments
Open

Email Aliases in Drop Down for BCC Maps under Address Rewriting #3713

soulsymphonies opened this issue Aug 18, 2020 · 18 comments

Comments

@soulsymphonies
Copy link
Contributor

soulsymphonies commented Aug 18, 2020

Is your feature request related to a problem? Please describe.
I'm using mailpiler as my email archival software, I'm using BCC maps under the "Address Rewriting" to foward the emails to mailpiler's SMTP server, this works beautifully.

But I have some mailboxes that use alias adresses additionally to their main email address and mails to and from those alias addresses should also be archived.

As aliases are not shown in the drop down when I choose to create a new BCC map, the only way I have to forward those mails is to use the entire email domain in the drop down list. The issue with this is that this also forwards and therefore archives all email to and from that email domain but not all email addresses should be archived.

I tried to use a second forward to mailpiler in the aliases section, but this then only archives incoming emails to that alias address and not outgoing emails.

Describe the solution you'd like
Would it maybe be possible to add aliases that are given to mailboxes to the drop down menu in BCC maps, so that I could selectively forward mail to mailpiler to archive it?

Thank you ever so much.

@andryyy
Copy link
Contributor

andryyy commented Aug 20, 2020

Hi :)

Aliases cannot be used for BCC in Postfix. You can use the API to script that, perhaps?

@stale
Copy link

stale bot commented Oct 24, 2020

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the dunno label Oct 24, 2020
@stale stale bot closed this as completed Nov 1, 2020
@soulsymphonies
Copy link
Contributor Author

A few months later now, I tried another thing, which actually works and proves that postfix happily does BCC forwards for aliases.

I added additional hash tables for sender and recipient bcc via extra.cf

Original: main.cf
recipient_bcc_maps = proxy:mysql:/opt/postfix/conf/sql/mysql_recipient_bcc_maps.cf
sender_bcc_maps = proxy:mysql:/opt/postfix/conf/sql/mysql_sender_bcc_maps.cf

Overwrite: extra.cf
recipient_bcc_maps = proxy:mysql:/opt/postfix/conf/sql/mysql_recipient_bcc_maps.cf, proxy:hash:/opt/postfix/conf/extra/recipient_bcc_maps

sender_bcc_maps = proxy:mysql:/opt/postfix/conf/sql/mysql_sender_bcc_maps.cf, proxy:hash:/opt/postfix/conf/extra/sender_bcc_maps

I also added the necessary files sender_bcc_maps and recipient_bcc_maps into the folder data/conf/postfix/extra/ with the following content:

After docker-compose exec postfix-mailcow postmap /opt/postfix/conf/extra/sender_bcc_maps && postmap /opt/postfix/conf/extra/recipient_bcc_maps and a postfix container restart, postfix happily forwards alias addresses via BCC wherever desired.

But still this would be much easier to do, if I could use the WebUI Address forwarding, which would do the same via a MySQL query.

@andryyy
Copy link
Contributor

andryyy commented May 6, 2021

There must have been a show stopper I cannot remember right now...

There was a problem and I don't want to merge that to master to find out a week later why. I tested this. :/

@soulsymphonies
Copy link
Contributor Author

It's all fine, then I will continue to do it the hash-table way, I will test it for a few weeks and see if some issue comes up.

@andryyy
Copy link
Contributor

andryyy commented May 6, 2021

Yes, please. Let's open it up.

@andryyy andryyy reopened this May 6, 2021
@stale stale bot removed the dunno label May 6, 2021
@soulsymphonies
Copy link
Contributor Author

Thank you @andryyy

So far, tests are running well.

The actual mailbox BCCs defined in the Mailcow UI still work normally with the additionally added hash table.

The extra alias BCCs from the hash tables work also as expected, this goes even so far that [email protected] is also forwarded without additional lines to be added to the has table.

So basically when [email protected] is defined for forwarding to [email protected], things like [email protected] and [email protected] are forwarded also, which is the desired behavior.

So I will continue to watch this.

@soulsymphonies
Copy link
Contributor Author

soulsymphonies commented May 9, 2021

Everything still working wonderfully, all alias mails are forwarded as expected to my email archive.
Everything else works normally, too.

I'm getting the expected log entries in postfix, because I'm using extra.conf

/usr/sbin/postconf: warning: /opt/postfix/conf/main.cf, line 162: overriding earlier entry: recipient_bcc_maps=proxy:mysql:/opt/postfix/conf/sql/mysql_recipient_bcc_maps.cf, proxy:hash:/opt/postfix/conf/extra/recipient_bcc_maps
/usr/sbin/postconf: warning: /opt/postfix/conf/main.cf, line 163: overriding earlier entry: sender_bcc_maps=proxy:mysql:/opt/postfix/conf/sql/mysql_sender_bcc_maps.cf, proxy:hash:/opt/postfix/conf/extra/sender_bcc_maps
/usr/sbin/postconf: warning: /opt/postfix/conf/main.cf, line 203: overriding earlier entry: recipient_bcc_maps=proxy:mysql:/opt/postfix/conf/sql/mysql_recipient_bcc_maps.cf
/usr/sbin/postconf: warning: /opt/postfix/conf/main.cf, line 204: overriding earlier entry: sender_bcc_maps=proxy:mysql:/opt/postfix/conf/sql/mysql_sender_bcc_maps.cf

I've been running pflogsumm reports the last two days also, everything there looks good as well.

It seems, this thing is working with the extra hash table, so it should work via mysql and gui as well.
I would be wiling to test this with mysql and the gui also if that would help, but I don't know which files and how to change them.

@andryyy: What do you think?

@soulsymphonies
Copy link
Contributor Author

To further test this, after some research and refreshing my mysql knowledge, I removed the hash tables again and manually added entries (deactivated) for my aliasses into the bcc_maps table of mailcow (taking care that I would have no conflicting id's)

I had to do it this way, since I don't know where the SELECT statement for the drop down menu in the web UI is defined ;-)

INSERT INTO `bcc_maps` (`id`, `local_dest`, `bcc_dest`, `domain`, `type`, `created`, `modified`, `active`) 
VALUES (12, '[email protected]', '[email protected]', 'domain1.de', 'sender', current_timestamp(), NULL, '0'), 
(13, '[email protected]', '[email protected]', 'domain1.de', 'rcpt', current_timestamp(), NULL, '0') 

Afterwards I opened the web UI under "Configuration" -> "Mail setup" -> "Adress rewriting"
There I can now see the alias entries as I see all other forward entries for mailboxes.
Finally I activated the entries via the web UI.

Everything works fine, exactly as with the hash tables.

Nothing broken, no errors or failures, mailcows postfix just happily continues to "mooo" :D and joyously forwards the mails to the alias addresses to my mailpiler instance

By the way, did I already mention that I love Mailcow and I really appreciate the great work! A big thank you to all contributors!

@soulsymphonies
Copy link
Contributor Author

soulsymphonies commented May 19, 2021

@andryyy: Just wanted to give new feedback, it is now running for 2 weeks without any issues.

@andryyy
Copy link
Contributor

andryyy commented May 19, 2021 via email

@andryyy
Copy link
Contributor

andryyy commented May 31, 2021

@soulsymphonies I will rewrite the BCC stuff to use Rspamd. This will also prevent MX-based access maps (like using a regex to determine the next hop by MX record) to apply to BCC (@patschi).

I think we should simply always include all aliases to BCC then (direct and shared). What do you think? The alternative way would be to make it selectable.

@soulsymphonies
Copy link
Contributor Author

@andryyy: Thank you, sounds like a sound idea to use rspamd, I'm always amazed how you come up with such great solutions.

Would it mean a lot of extra work for you, when we would have an option to have the choice "forward all aliases (direct and shared)" and "forward only selected aliases" and then the opportunity to select them individually?

Because I feel that I doesn't always make sense to automatically forward all shared aliases,

@soulsymphonies
Copy link
Contributor Author

Thank you, I've seen you have already added the aliases to the drop down list in BCC, I don't know why but when I select one of the aliasses I get the following message of the Web UI "Access denied or invalid form data", maybe a permission issue although I'm logged in as full administrator?

@andryyy
Copy link
Contributor

andryyy commented Jun 5, 2021

@soulsymphonies Sorry, I forgot about that... :) It is fixed now.

The option to toggle all aliases is not there yet. :(

@soulsymphonies
Copy link
Contributor Author

soulsymphonies commented Jun 5, 2021 via email

@normanu
Copy link

normanu commented Jul 5, 2021

I was using this function as well for mail archiving purposes.
Now it seems, address rewriting is still working on recipient addresses.
But no long on the sender ones, no BCC is received.

Is there something that needs to be changed anywhere?

@gpz1100
Copy link

gpz1100 commented Jul 29, 2023

@soulsymphonies or @andryyy

How does this work when the alias is the @domain.com catchall? How does the alias/bcc get defined?

Specifically, I want mail destined for nonexistent mailboxes to be forwarded to a mailcow mailbox ([email protected]) AND forwarded to an external [email protected].

Defining both [email protected] and [email protected] as targets of @domain.com works, but doesn't go through rspamd so no anonymizing of headers. When it gets processed as BCC (address rewrite/bcc map/recipient map), local headers are stripped when received at [email protected].

image

Suggestions?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants