1

I want to loadbalance outbound emails via multiple IPs, is there any built-in tool or some easy way to do it with postfix, sendmail or exim? for example if I assign three IPs to the email server and emails are sent via all the ips one by one.

3

If you want send mails from different Ip's from a single mail server than you should think about postfix multiple instance on a single host. And you can assign a different Ip address for each instance and your null instance will submit mails for each instance. for more detail you may refer these links This one for how to assign Ip and all http://souptonuts.sourceforge.net/postfix_sbr.html and this for all basic information how we create and how instance works http://www.postfix.org/MULTI_INSTANCE_README.html

  • the references are good, actually I am using that technique so we can setup bulk email server and do not get blocked our IP. is this some good solution you think? – Toqeer Sep 11 '12 at 5:41
  • 2
    If you want to prevent your Ip from blacklisting than you should use subscribed mailling lists and if you want to hide your Ip than you are categorised as spamer. – user128296 Sep 11 '12 at 6:06
  • one or other way our users are subscribed to the list but that are huge in numbers so I am just scared that our IP does not block, what about mailchimp, if some of their clients send emails which are unsolicted would their IPs get blocked? what mechanism they use to send emails? – Toqeer Sep 11 '12 at 8:49
  • you should go mailchimp terms and conditions. they block the user if user sends mail more than one mail per 1000 as spam. – user128296 Sep 11 '12 at 9:21
6

With Postfix 2.7 or later it's pretty easy.

First create one entry for each IP in master.cf, like this:

out1  unix -       -       n       -       -       smtp
      -o syslog_name=postfix-out1
      -o smtp_helo_name=out1.yourdomain.tld
      -o smtp_bind_address=a.b.c.1
out2  unix -       -       n       -       -       smtp
      -o syslog_name=postfix-out2
      -o smtp_helo_name=out2.yourdomain.tld
      -o smtp_bind_address=a.b.c.2
[...]
outN  unix -       -       n       -       -       smtp
      -o syslog_name=postfix-outN
      -o smtp_helo_name=outN.yourdomain.tld
      -o smtp_bind_address=a.b.c.N

Then create a sender dependent transport map in main.cf, like this:

sender_dependent_default_transport_maps = mysql:/etc/postfix/config/transport_roundrobin.cf

Comment out all the other transport_maps in main.cf, like this:

#transport_maps = ...

Now here is the trick, this transport table will be using RAND() to randomize usage of all the out[1..n] transports listed in master.cf.

In /etc/postfix/config/transport_roundrobin.cf write:

user = dbuser
password = dbpass
dbname = dbname
hosts = dbhost
query = SELECT transport FROM transport_roundrobin ORDER BY RAND() LIMIT 1

Finally, create a table called 'transport_roundrobin' on db 'dbname' running on 'dbhost' and insert one row for each transport:

CREATE TABLE transport_roundrobin (transport varchar(40) not null)
INSERT INTO transport_roundrobin (transport) VALUES ('out1');
INSERT INTO transport_roundrobin (transport) VALUES ('out2');
[...]
INSERT INTO transport_roundrobin (transport) VALUES ('outN');

Postfix will select a random row from the transport_roundrobin mysql table and then use the value obtained to select the corresponding transport in master.cf. Each transport will use a different ip address, according to -o smtp_bind_address

  • can this be done somehow without mysql? – Nick May 31 '16 at 16:08
  • AFAIK NO, you'd need to patch postfix – Luca Gibelli May 31 '16 at 16:12
  • is very helpful in all cases. those techniques are often used for spam and nobody usually comment them. – Nick Jun 1 '16 at 9:58
  • I can confirm I tried this yesterday and work like a charm. I had to manually upgraded postfix to 2.7 because centos supports earlier version where this does not work (but does not give any errors as well?!?! ) . Server is still not in use, but it looks it will need much less resources compared to my old install with 16 postfix instances running in parallel. Thanks a lot! – Nick Dec 9 '16 at 6:16
2

Check this solution if using postfix 3, it uses randmap, so you won't need mysql's RAND() function. https://shami.blog/2016/04/randomize-source-ip-addresses-with-postfix/

You can do the master.cf config suggested already, and add the following the main.cf (assuming you have 3 entries in master.cf):

sender_dependent_default_transport_maps = randmap:{out1,out2,out3}
smtp_connection_cache_on_demand=no

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.