Saturday, January 8, 2011

Distributing your outgoing mails from Multiple IP addresses

Some mail providers like hotmail, yahoo restrict the number of connections from a single IP and the number of mails that can be delivered in an hour from a single IP. To increase your ability to deliver large number of genuine emails from your users to such sites, you may want to send out mails from multiple IP addresses.

IndiMail has the ability to call a custom program instead of qmail-local(8) or qmail-remote(8). This is done by defining the environment variable QMAILLOCAL or QMAILREMOTE. qmail-remote(8) can use the environment variable OUTGOINGIP to set the IP address of the local interface when making outgoing connections. By writing a simple script and setting QMAILREMOTE environment variable pointing to this script, one can randomly chose an IP address from the control file


The script below also allows you to define multiple outgoing IP addresses for a single host. e.g. you can create the control file to send out mails from multiple IPs only for the domain


Let us name the below script balance_outgoing

% su
# echo "/var/indimail/bin/balance_outgoing" > /service/qmail-send.25/variables/QMAILREMOTE
# svc -d /service/qmail-send.25
# svc -u /service/qmail-send.25
# exit

Finally the balance_outgoing script can be placed with execute bit in /var/indimail/bin

# This scripts expects qmail-remote arguments on command line
# argv0          - qmail-remote
# argv1          - host   (host)
# argv2          - sender (sender)
# argv3          - qqeh   (qmail queue extra header)
# argv4          - size
# argv5 .. argvn - recipients
shift 4

cd /var/indimail
if [ " $CONTROLDIR" = " " ] ; then
if [ -n "$SPAMFILTER" -o -n "$FILTERARGS" -o -f $FN ] ; then
    # execute spawn-filter if you have filters defined for remote/local deliveries
if [ " $CONTROLDIR" = " " ] ; then
    if [ -f /var/indimail/control/outgoingip.$host ] ; then
        IP=(`cat /var/indimail/control/outgoingip.$host`)
    elif [ -f /var/indimail/control/outgoingip ] ; then
        IP=(`cat /var/indimail/control/outgoingip`)
        exec -a qmail-remote $PROG "$host" "$sender" "$qqeh" $size $*
    if [ -f $CONTROLDIR/outgoingip.$host ] ; then
        IP=(`cat $CONTROLDIR/outgoingip.$host`)
    elif [ -f $CONTROLDIR/outgoingip ] ; then
        IP=(`cat $CONTROLDIR/outgoingip`)
        exec -a qmail-remote $PROG "$host" "$sender" "$qqeh" $size $*
if [ $IP_COUNT -gt 1 ] ; then
    i=`expr $RANDOM % $IP_COUNT`
    export OUTGOINGIP=${IP[$i]}
exec -a qmail-remote $PROG "$host" "$sender" "$qqeh" $size $*

No comments:

IndiMail Queue Mechanism

Indimail has the ability of configuring multiple local and remote queues. A queue is a location on your hard disk where email are deposited ...