3

i've got exim4 on ubuntu server and i-ve got a pool of 20 external IP's.

Is that possible to configure exim4 to use this ip-s rotating to send mail?


I think i could do this with iproute / iptables load balancing with "link stick" but i want to know if this is possible with exim4 internal configuration. Maybe there i should create several external smtp_drivers that will be using one of 20 IP and some random() func ?

3
  • 1
    Why would you want to?
    – Zoredache
    Jan 31, 2012 at 8:39
  • say you want to send 2k emails to server gmail.com but after 1k gmailcom says: "Hey, you've excided maximum allowed emails from ip, try later". This later is 30/60/120 minutes but i have to deliver mail within 30 min.
    – MealstroM
    Jan 31, 2012 at 11:12
  • You are just digging yourself deeper into the hole if you try to evade their policy restrictions. See what you can do to simply send less email into Gmail, or get a proper agreement with them to have you exempted from the restriction.
    – tripleee
    Mar 6, 2015 at 12:50

4 Answers 4

3

I found this article which show how to sets up a random function to pick an IP from a list and then assign it as an output interface to the smtp driver.

Essentially, you have to set up a function:

sub randinet {
  @inet = ("x.x.x.1", "x.x.x.2", "x.x.x.3", "x.x.x.4");
  return $inet[int rand($#inet+1)];
}

and modify the smtp driver:

remote_smtp:
driver = smtp
interface = "${perl{randinet}}"
4

You can do this from within exim as well without using perl:

create a lookup file /etc/exim/ips.txt with

1: xxx.xxx.xxx.1
2: xxx.xxx.xxx.2
3: xxx.xxx.xxx.3
4: xxx.xxx.xxx.4

Set the transport to:

remote_smtp:
  driver = smtp
  interface = "${lookup {${randint:5}} lsearch {/etc/exim/ips.txt}}"

randint will return a random number between 1-4 which is then looked up in the file and used if you have more ip's just add to the list and increment the randint value to number ips + 1

Can be used by those who have exim built without perl or just don't want to use perl keeping everthing within exim.

2
  • Are the quotations necessary? ${lookup {${randint:5}} lsearch {/etc/exim/ips.txt}}"
    – user158722
    Feb 12, 2013 at 23:44
  • According to exim.org/exim-html-current/doc/html/spec_html/… randint:5 should produce a value between 0 and 4, that means 0, 1, 2, 3 or 4. Your list starts with 1, not zero. Is this correct?
    – Christian
    Apr 23, 2022 at 14:16
0

Here's a very easy way

create /etc/exim.pl with the following content:

use feature qw[state];

sub randomhosts {
  state $current;

  my @inet = (
    "x.x.x.x:hostname1.domain.com",
    "x.x.x.x:hostname2.domain.com",
    "x.x.x.x:hostname3.domain.com"
  );

  if ($_[0] eq 'generate') {
    shift;
    @{$current}{qw[ip host]} = split /:/, $inet[rand @inet];
  }

  return $current->{$_[0]};
}

Replace the x.x.x.x with IP and the hostname ( after colon, which will be used as HELO).

Now add this to top of your exim.conf

perl_startup = do '/etc/exim.pl'

Now, under remote_smtp: section append this

  interface = "${perl{randomhosts}{generate}{ip}}"
  helo_data = "${perl{randomhosts}{host}}"

That's it. Now emails will randomly go through all the IPs you added to Perl script, and will use the valid HELOs.

-1

You will get the following error if you follow topdog's approach.

there are two transports called "remote_smtp"

as you cannot change the STARTTRANSPORT section in exim conf editor.

Even if you try to change exim.conf manually, it will be wiped out and replaced with the default one on restart.

The only solution I could find on the internet was http://forums.cpanel.net/f43/scripts-posteximup-help-205971.html#post845302

I have also posted a ticket to cPanel. lets see how they respond. Will try to update it once I receive a response.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .