Add X-Original-To headers to mails

Discussion in 'Tips/Tricks/Mods' started by pyte, Sep 9, 2024.

  1. pyte

    pyte Well-Known Member HowtoForge Supporter

    Hi,
    after migrating our mail servers to an ISPConfig environment, we have noticed that we are experiencing issues with some emails that follow a specific pattern. In our setup, all emails are routed to a single mailbox [email protected]. All recipient addresses that exist on the underlying Exchange server are configured as aliases for this mailbox. Unlike a regular catchall mailbox, this setup helps to better avoid spam and allows for other specific configurations with additional mailboxes.

    However, we have noticed that a problem occurs in the following situation: When someone from outside sends an email with more than one recipient from our domain in the BCC field, the header lacks the information about who the original recipient is. This causes an issue when retrieving the email through PopCon, as it doesn't know where to route the email.

    To resolve the issue, I initially attempted to activate the "X-Original-To" header using the Postfix option "enable_original_recipient = yes" and flags in the master.cf file, but this approach was unsuccessful. Although I believe this issue is due to the fact that "receive_override_options = no_address_mappings" is required, I was unable to assess the potential consequences of this setting.

    So, to help others who might encounter the same issue, I decided to share what I did instead to solve this problem.

    I then set up a working configuration using "smtpd_recipient_restrictions." To achieve this, I added the following to the "smtpd_recipient_restrictions":
    Code:
    smtpd_recipient_restrictions = ... check_recipient_access regexp:/etc/postfix/ra_xoriginalto ...
    
    In the file /etc/postfix/ra_xoriginalto, I added the line:
    Code:
    /(.+)/ prepend X-Original-To: $1
    After restarting, the original recipient now appears in the "X-Original-To" header field in all emails.
    To make these changes persistent, I added the configuration to /usr/local/ispconfig/server/conf-custom/install/postfix_custom.conf.master.

    Be aware that this is not a good solution in some cases as it might results in privacy issues when other users can see other BCC recipients.
     
    Last edited: Sep 9, 2024

Share This Page