Force sendmail to route mail to specific hosts or mailserver

Posted on in Categories last updated April 20, 2006

mailertable allows you to route or deliver mail to different hosts. You need to use feature called FEATURE(`mailertable’) and you will have to create an external database containing the routing information for various domains.

First include mailertable feature you need to edit your sendmail.mc file and add the following line:
FEATURE(`mailertable’):

Open sendmail config file using text editor:

# vi /etc/mail/sendmail.mc

Append/modify line as follows:

FEATURE(`mailertable’)

Regenerate sendmail configuration file using m4:

m4 /etc/mail/sendmail.mc > /etc/mail/sendmail.cf

Restart sendmail service:

# /etc/init.d/sendmail restart

Open /etc/mail/mailertable file and add domain name to route to different hosts. For example all mail coming from network 192.168 route to mail.myisp.com and all email for nixcraft.com will be automatically forwarded to a mail server p5.mail4india.com:

# vi /etc/mail/mailertable

Append following lines:

192.168. smtp:mail.myisp.com
nixcraft.com smtp:p5.mail4india.com

Now build database version of the mailertable is built using:

# makemap hash /etc/mail/mailertable Or just type make command to build new mailertable.db file:
# make

See also:

Posted by: Vivek Gite

The author is the creator of nixCraft and a seasoned sysadmin and a trainer for the Linux operating system/Unix shell scripting. He has worked with global clients and in various industries, including IT, education, defense and space research, and the nonprofit sector. Follow him on Twitter, Facebook, Google+.

4 comment

  1. I have a centos & I use sendmail as mail server.
    In sendmail.cf I had put an IP Address of relay server. & All mail is sending properly but My mail server administrator told me to put host name instead of IP address in SmartHost Ds in sendmail.cf & I done it but I cant send mail to anybody & I got an error —

    451 4.4.1 reply: read error from smtp.sss.in.

    Please anybody tell me How can I send mail to outside via my relay using host name & what should I do?

  2. Hi,
    I have mail server on redhat and its sendmail configured as relay for office 365 mail services

    It was wokring fine for 3 months but now its not working as expected mails are getting very slow delivered with delay from 30 minutes to 24 or 48 hours

    These are output of error

    Jun 7 18:55:25 app2 sendmail[82004]: v57D4r4a061245: to=, delay=00:20:32, xdelay=00:00:00, mailer=esmtp, pri=212172, relay=…..mail….ction.outlook.com., dsn=4.0.0, stat=Deferred: Connection timed out with ….-com.mail.protection.outlook.com.

Leave a Comment