How to Send Mail from Multiple IPs in Exim

by dt on October 28th, 2009

Sometimes you need to configure exim mail server to use multiple IPs for sending mail (for example, when you host a newsletter with too many subscribers) . By default, exim is bound to primary interface, but this can be changed.

Please note that this will break “mailip” feature from cPanel (that allow users with dedicated IPs to send mail from these instead of main server IP). Also, if you enabled SPF, take care to add all new IP addresses to the list of allowed IPs.

First, you need a function that pick a random IP from a list. Add it to /etc/exim.pl (somwhere at the end, above last line)

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)];
}

Then edit /etc/exim.conf and search for a line that start with “interface=”

remote_smtp:
driver = smtp
interface = ${if exists {/etc/mailips}{${lookup{$sender_address_domain}lsearch*{/etc/mailips}{$value}{}}}{}}

replace last line with

interface = "${perl{randinet}}"

You can do the same for dk_remote_smtp section (this is used for sending signed mails). Restart exim and search the logs for possible errors.

shorturl: