≡ Menu

Force sendmail to route mail to specific hosts or mailserver

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:

Open sendmail config file using text editor:

# vi /etc/mail/sendmail.mc

Append/modify line as follows:


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:

Share this tutorial on:

Your support makes a big difference:
I have a small favor to ask. More people are reading the nixCraft. Many of you block advertising which is your right, and advertising revenues are not sufficient to cover my operating costs. So you can see why I need to ask for your help. The nixCraft, takes a lot of my time and hard work to produce. If you use nixCraft, who likes it, helps me with donations:
Become a Supporter →    Make a contribution via Paypal/Bitcoin →   

Don't Miss Any Linux and Unix Tips

Get nixCraft in your inbox. It's free:

{ 3 comments… add one }
  • nilesh December 24, 2006, 8:33 am

    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?

  • relocation July 18, 2007, 2:09 am

    How can we use the other port?

    for example,use port 2525.

  • Martin Dahl-Larsen January 7, 2012, 11:45 pm

    Hi there

    Just add this line to sendmail.mc
    and rebuild


Leave a Comment

You can use these HTML tags and attributes: <strong> <em> <pre> <code> <a href="" title="">

   Tagged with: