Background: I have an issue with an ISP in our region that has arbitrarily blocked our IP for emails heading into their domain. While we work to get that sorted, my data center has provided a relay host so that our messages can be delivered. This, of course, involves adding entries to /etc/postfix/imscp/transport, which we have done manually as a work-around. This led me to this thread:
I am working on a listener to enforce entries in /etc/postfix/imscp/transport, but while I am a coder from way back, I am really a coder from waaaaaay back. If I can get this working, it will be my first humble code contribution to the i-MSCP universe. Here is what I have so far (based on 10_system_hosts.pl
- # i-MSCP Listener::System::Transport listener file
- # Copyright (C) 2015-2017 Laurent Declercq <l.declercq@nuxwin.com>
- # and Matthew L. Hill <m.hill@innodapt.com>
- #
- #
- # # # #### # # # #
- # # # # # # # # # # #
- # ##### # #### ##### ##### #
- # # # # # # # # #
- # # # ##### # # # # # #
- #
- #
- # This library is free software; you can redistribute it and/or
- # modify it under the terms of the GNU Lesser General Public
- # License as published by the Free Software Foundation; either
- # version 2.1 of the License, or (at your option) any later version.
- #
- # This library is distributed in the hope that it will be useful,
- # but WITHOUT ANY WARRANTY; without even the implied warranty of
- # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- # Lesser General Public License for more details.
- #
- # You should have received a copy of the GNU Lesser General Public
- # License along with this library; if not, write to the Free Software
- # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
- #
- ## Allows to add entries in the postfix transport file (eg. /etc/postfix/imscp/transport).
- #
- package Listener::Postfix::Transport;
- use strict;
- use warnings;
- use iMSCP::Debug;
- use iMSCP::EventManager;
- use iMSCP::File;
- #
- ## Configuration variables
- #
- # Path to postfix transport file
- my $transportFilePath = '/etc/postfix/imscp/transport';
- # Parameter which allow to add one or many entries in the postfix transort file
- # Please replace the entries below by your own entries
- my @transportFileEntries = (
- 'recipientdomain.tld relay:my.smtprelay',
- 'user2@domain.tld smtp:some-other-host'
- );
- #
- ## Please, don't edit anything below this line
- #
- # Listener responsible to add entries in the postfix transport file, once it was built by i-MSCP
- iMSCP::EventManager->getInstance()->register(
- 'afterSetupServerHostname',
- sub {
- return 0 unless -f $transportFilePath;
- my $file = iMSCP::File->new( filename => $transportFilePath );
- my $fileContent = $file->get();
- unless (defined $fileContent) {
- error( sprintf( 'Could not read %s file', $transportFilePath ) );
- return 1;
- }
- my $rs = $file->set( $fileContent.( join "\n", @transportFileEntries )."\n" );
- $rs ||= $file->save();
- #
- #### NEED TO TRIGGER A POSTMAP OF THE TRANSPORT FILE HERE ###
- #
- }
- );
- 1;
- __END__
I have two questions:
- Is “afterSetupServerHostname” a good trigger for this event, or would you recommend something else?
- I do not have a clue how to trigger the necessary “postmap /etc/postfix/imscp/transport” from this file. Feeling pretty stupid here, but at least I am smart enough to know when I am stupid—and that is one good step in the direction of being a little less being stupid!
Thank you so very much for your help with this, and for all you do to make our lives better through i-MSCP!