Postfix Mail Rotate outgoing

Rafael Carvalho

New Member
Apr 20, 2019
2
1
1
44
Hi!
We currently uses the routing of e-mails through different internet links (multiples mx to send e-mails).
I use the script below for this purpose, that changes the parameter hostname of postfix, and in my firewall I rotate a source for output for a specific link)

/etc/postfix/random.pl

01 #!/usr/bin/perl -w
02 # author: Hari Hendaryanto <hari.h -at- csmcom.com>
03
04 use strict;
05 use warnings;
06 use Sys::Syslog qw(:DEFAULT setlogsock);
07
08 #
09 # our transports array, we will define this in master.cf as transport services
10 #
11
12 our @array = (
13 'rotate1:',
14 'rotate2:',
15 'rotate3:',
16 'rotate4:',
17 'rotate5:'
18 );
19
20 #
21 # Initalize and open syslog.
22 #
23 openlog('postfix/randomizer','pid','mail');
24
25 #
26 # Autoflush standard output.
27 #
28 select STDOUT; $|++;
29
30 while (<>) {
31 chomp;
32 # randomizing transports array
33 my $random_smtp = int(rand(scalar(@array)));
34 if (/^get\s(.+)$/i) {
35 print "200 $array[$random_smtp]\n";
36 syslog("info","Using: %s Transport Service", $random_smtp);
37 next;
38 }
39
40 print "200 smtp:";
41 }


/etc/postfix/master.cf
1 127.0.0.1:2527 inet n n n - 0 spawn
2 user=nobody argv=/etc/postfix/random.pl


01 # random smtp
02 rotate1 unix - - n - - smtp
03 -o syslog_name=postfix-rotate1
04 -o smtp_helo_name=smtp1.example.com
05 -o smtp_bind_address=1.2.3.1
06
07 rotate2 unix - - n - - smtp
08 -o syslog_name=postfix-rotate2
09 -o smtp_helo_name=smtp2.example.com
10 -o smtp_bind_address=1.2.3.2
11
12 rotate3 unix - - n - - smtp
13 -o syslog_name=postfix-rotate3
14 -o smtp_helo_name=smtp3.example.com
15 -o smtp_bind_address=1.2.3.3
16
17 rotate4 unix - - n - - smtp
18 -o syslog_name=postfix-rotate4
19 -o smtp_helo_name=smtp4.example.com
20 -o smtp_bind_address=1.2.3.4
21
22 rotate5 unix - - n - - smtp
23 -o syslog_name=postfix-rotate5
24 -o smtp_helo_name=smtp5.example.com
25 -o smtp_bind_address=1.2.3.5


main.cf

1 transport_maps = tcp:[127.0.0.1]:2527
2 127.0.0.1:2527_time_limit = 3600s


Is there via GUI this kind of configuration?
Is there any way I can modify the settings of main.cf and master.cf for this purpose? These extra settings will be lost when using GUI I save the settings or in case of update?

Thanks!

Rafael Carvalho
 
* Since PMG is using Postfix in a version > 3 the following blog-post
could describe a workable setup for your situation:
https://shami.blog/2016/04/randomize-source-ip-addresses-with-postfix/

To integrate the needed configuration changes to postfix follow the pmg-admin-guide
(https://www.proxmox.com/images/download/pmg/docs/pmg-admin-guide.pdf
section 4.3 'Service Configuration Templates')
That way your changes will persist across upgrades

Hope this helps!
Hello
I'm working with random source ip address , I'm checking that my sent message appears "queued/accepted" but the recipient receives the correct message

main.cf
sender_dependent_default_transport_maps =
randmap:{relay1,relay2,relay3,relay4,relay5}
smtp_connection_cache_on_demand=no

master.cf
relay1 unix - - n - - smtp
-o smtp_bind_address=IP1
-o smtp_helo_name=foo1.bar.com
-o syslog_name=relay1
relay2 unix - - n - - smtp
-o smtp_bind_address=IP2
-o smtp_helo_name=foo2.bar.com
-o syslog_name=relay2
relay3 unix - - n - - smtp
-o smtp_bind_address=IP3
-o smtp_helo_name=foo3.bar.com
-o syslog_name=relay3
relay4 unix - - n - - smtp
-o smtp_bind_address=IP4
-o smtp_helo_name=foo4.bar.com
-o syslog_name=relay4
relay5 unix - - n - - smtp
-o smtp_bind_address=IP5
-o smtp_helo_name=foo5.bar.com
-o syslog_name=relay5