Implement sender rewriting scheme in an ISPConfig mailserver part 2

Discussion in 'Tips/Tricks/Mods' started by remkoh, Nov 29, 2022.

  1. remkoh

    remkoh Active Member

    Part 1 of this tutorial can be found here:
    Where the basic installation of Postsrsd and implementation in Postfix is covered.

    Part 2 covers the recovery of the broken functionality behind ISPConfig's ability to configure a relayhost per domain and entire host.

    For this we need to setup a second Postfix instance.
    I've called mine "postfix-relay" in group "mta" and will be running it on port 2525.

    Create the second instance:
    postmulti -e init
    postmulti -I postfix-relay -G mta -e create
    Copy /etc/postfix/ to /etc/postfix-relay/

    Delete lines in /etc/postfix-relay/
    dovecot_destination_recipient_limit = 1
    smtpd_sasl_type = dovecot
    smtpd_restriction_classes = greylisting
    greylisting = check_policy_service inet:
    smtpd_milters = inet:localhost:11332
    non_smtpd_milters = $smtpd_milters
    milter_protocol = 6
    milter_mail_macros = i {mail_addr} {client_addr} {client_name} {auth_authen}
    milter_default_action = accept
    multi_instance_wrapper = ${command_directory}/postmulti -p --
    multi_instance_enable = yes
    multi_instance_directories = /etc/postfix-relay
    multi_instance_group = mta
    Change lines in /etc/postfix-relay/
    inet_interfaces = all
    inet_protocols = all
    inet_interfaces = loopback-only
    inet_protocols = ipv4
    Change in /etc/postfix-relay/
    smtpd      inet  n       -       y       -       -       smtpd
    Code:      inet  n       -       y       -       -       smtpd
    Enable and start the second instance of Postfix:
    postmulti -i postfix-relay -e enable
    postmulti -i postfix-relay -p start
    I had issues with resolving domains in Postfix because not all chroot related folders where created.
    This was solved with a reboot of the server.

    Now that the second instance of Postfix is up and running we need to relay emails to it after they've gone through Postsrsd.

    Change in /etc/postfix/
    Code: inet n - n - - smtpd
            -o content_filter=smtp:
    Code: inet n - n - - smtpd
            -o content_filter=smtp:
    and restart Postfix.

    Because we copied from Postfix' primary instance to the secondary instance all mysql hooks to ISPConfig settings are kept intact.
    Including relaying a domain to another host from within ISPConfig's settings!

    Only manual action left for a sysadmin is when you set a relay host for the entire host in ISPConfig.
    Find lines like these in /etc/postfix/
    relayhost = ...
    smtp_sasl_auth_enable = yes
    smtp_sasl_security_options = ...
    smtp_sasl_tls_security_options = ...
    smtp_sasl_password_maps = ...
    and copy to or replace them in /etc/postfix-relay/

    I've automated this last manual step with a cronjob that runs a simple search&replace script every 5 minutes.
    See the comment below.

    This concludes the tutorials on how to install and implement Sender Rewriting Scheme in an ISPConfig Perfect Server.
    Last edited: Dec 2, 2022
    till likes this.
  2. remkoh

    remkoh Active Member

    If I'm not mistaking relayhost settings are available in ISPConfig's database.
    So when a mysql hook can be implemented in Postfix then it replaces the sysadmin manual action and all is automated directly from ISPConfig again.
    Same as sender relayhost already does.
  3. remkoh

    remkoh Active Member

    I found that Postfix doesn't support mysql queries in relayhost.
    So I'll create a script to check for changes in relayhost settings in Postfix' primary instance and replicate it to the second instance to restore ISPConfig's function.
  4. remkoh

    remkoh Active Member

    Made a quick (and probably dirty ;)) script that:
    • searches for relevant relayhost lines in Postfix' primary instance
    • searches for the same relevant relayhost lines in Postfix' secundary instance
    • compares the lines from both
    • replaces a line in Postfix' secundary instance with the line found in Postfix' primary instance if a difference between the two is found
    • reloads Postfix, only if differences were found
    A cronjob runs the script every 5 minutes.

    The relevant relayhost lines to search for are put as strings in an array after which a loop does the search, compare and replacement if necessary for every string in the array.

Share This Page