Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

I need to rewrite the last part of our email address

Status
Not open for further replies.

Merlian

Programmer
Sep 23, 2002
5
GB
Hi

I need to somehow translate/forward a certain pattern of email address on our sendmail server.

e.g. I need sendmail to automatically rewrite:

123456789_at_fax@domain.com

to be

123456789@fax.domain.com

Can anyone help me do this please? (Or tell me if it is possible!)

Ian
 
we do something similar ...
we start sendmail without the timeout period in /etc/init.d/sendmail and then run a program every 15 minutes that 'sed's the file to change the '^S' lines into the correct ones.
 
Hi Jad

Sorry I'm not too familiar with sed.

Could you embelish this at all ? (a peek at the script would be great!)

Also does that mean it only receives mail every 15 minutes?

Sounds promising tho!

Ian
 
ok, our mail system receives all the time ... sendmail -s run with '/lib/sendmail -bd' not '/lib/sendmail -bd -q 15m'

this queues the files up in /var/spool/mqueue

every 15 minutes (approx) the mail is retrieved from this directory, passed through sed and delivered

file /etc/delivermail:
Code:
#!/bin/sh

MAILQUEUE="/var/spool/mqueue"
while [ 1 ] ; do
    if [ `ls -l ${MAILQUEUE} | grep -c "^-r"` -gt 0] ; then
    if ping post.demon.co.uk > /dev/null 2> /dev/null ; then
        /etc/preprocessmail
        /usr/lib/sendmail -q -oQ${MAILQUEUE}
    fi
    fi
    sleep 900
done

file /etc/preprocessmail:
Code:
#!/bin/sh

MAILQUEUE="/var/spool/mqueue"
SED="/opt/sfw/bin/gsed"
cd ${MAILQUEUE}

files="`echo qf* 2>/dev/null`"
if [ "$files" |= "qf*" ] ; then
    for f in $files ; do
        if [ -s $f ] ; then
            qf="${qffiles} $f"
        fi
    done
    dffiles=`echo "$qffiles" | ${SED} 's/ qf/ df/g'`
    if ["x$qffiles" |= "x" ] ; then
        for f in $qffiles ; do
            SEDSTR="s/_at_fax@domain.com/@fax.domain.com/g;"
            ${SED} "${SEDSTR}" $f > T$f
            if [ -s T$f ] ; then
                mv -f T$f $f
            fi
            rm -f T$f 2> /dev/null
        done
    fi
fi

i hope that works ...

i keep the scripts seperate so that i can run them manually if i need to.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top