Rewrite Postfix email sender with PostSRSd

postsrsd is a service that stands for “Postfix Sender Rewriting Scheme Daemon.” It is used in conjunction with the Sender Rewriting Scheme (SRS) to rewrite the sender address of email messages when forwarding or relaying them. This is often used to prevent email forwarding loops and ensure that forwarded emails pass SPF (Sender Policy Framework) checks.

To install and configure postsrsd on Ubuntu, follow these steps:

  1. Install postsrsd:

    You can install postsrsd using the package manager. Open a terminal and run:

    sudo apt update
    sudo apt install postsrsd
    
  2. Configure postsrsd:

    By default, postsrsd is configured to work with Postfix. You typically don’t need to make major changes to its configuration. However, you can customize the configuration in the /etc/default/postsrsd file if needed. To edit the configuration file, use a text editor like nano:

    sudo nano /etc/default/postsrsd
    

    You might need to specify the -s option with the Postfix UNIX socket path if it’s not using the default path.

  3. Restart postsrsd:

    After any changes to the configuration, you should restart the postsrsd service:

    sudo systemctl restart postsrsd
    
  4. Configure Postfix:

    To make Postfix work with postsrsd, you need to configure Postfix to use the SRS feature. Open the Postfix configuration file /etc/postfix/main.cf:

    sudo nano /etc/postfix/main.cf
    

    Add or modify the following lines to enable SRS:

    sender_canonical_maps = tcp:127.0.0.1:10001
    sender_canonical_classes = envelope_sender
    

    These settings tell Postfix to rewrite the sender address using postsrsd. Ensure that the sender_canonical_maps setting points to the correct postsrsd socket.

  5. Restart Postfix:

    After making changes to the Postfix configuration, restart the Postfix service to apply the changes:

    sudo systemctl restart postfix
    

postsrsd is now configured to rewrite sender addresses using the Sender Rewriting Scheme, which can help avoid SPF-related issues when forwarding or relaying email messages.