mailcow / mailcow-dockerized

mailcow: dockerized - 🐮 + 🐋 = 💕
https://mailcow.email
GNU General Public License v3.0
9.09k stars 1.19k forks source link

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

Open soulsymphonies opened 4 years ago

soulsymphonies commented 4 years ago

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 commented 4 years ago

Hi :)

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

stale[bot] commented 4 years ago

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.

soulsymphonies commented 3 years ago

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:

user-alias1@domain1.de forward@address.tld
user-alias2@domain2.de forward@address.tld

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 commented 3 years ago

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 commented 3 years ago

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 commented 3 years ago

Yes, please. Let's open it up.

soulsymphonies commented 3 years ago

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 user-alias1+something@domain1.de is also forwarded without additional lines to be added to the has table.

So basically when user-alias1@domain1.de is defined for forwarding to forward@address.tld, things like user-alias1+something@domain1.de and user-alias1+something2@domain1.de are forwarded also, which is the desired behavior.

So I will continue to watch this.

soulsymphonies commented 3 years ago

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 commented 3 years ago

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, 'user-alias1@domain1.de', 'forward@address.tld', 'domain1.de', 'sender', current_timestamp(), NULL, '0'), 
(13, 'user-alias1@domain1.de', 'forward@address.tld', '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 commented 3 years ago

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

andryyy commented 3 years ago

Thank you, I will try to add it soon. :)

Your testing is appreciated!

Am 19.05.2021 um 13:20 schrieb Robert Christian @.***>:

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

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub, or unsubscribe.

andryyy commented 3 years ago

@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 commented 3 years ago

@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 commented 3 years ago

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 commented 3 years ago

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

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

soulsymphonies commented 3 years ago

Thank you very much, I really appreciate your work.

Please, no hurry with the "toggle all aliases" :)

 

normanu commented 3 years ago

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 commented 1 year ago

@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 (user@domain.com) AND forwarded to an external email@extdomain.com.

Defining both user@domain.com and email@extdomain.com 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@extdomain.com.

image

Suggestions?

Corinari commented 1 month ago

While doing some testing for the situation that a BCC should be send for every incoming and sending email, i saw that there seems to be a issue when doing in the UI:

As of now, i configuried it via the *_bcc_maps like above, but with the line bcc_target@domain.tld ignorein both and it seems to work.