Technical article 105404

How can I configure sendmail to forward mail from a specific domain to a different domain?

OpenServer 5.0.0OpenServer 5.0.2

Written · Last revised

Problem

I would like to configure sendmail on my mail server to forward
mail addressed to a specific domain to a different domain.  I
don't want all of my mail to be forwarded, so I can't set up the
server to forward all mail to a different server.

Solution

As root, edit the file /usr/lib/sendmail.cf.
Go to Ruleset 0 by searching for the entry S0.  You should
see an entry that looks similar to the following:
# handle numeric address spec
R$* < @ [ $+ ] > $*     $: $>98 $1 < @ [ $2 ] > $3
R$* < @ [ $+ ] > $*     $#smtp $@ [$2] $: $1 < @ [$2] > $3

Make the following entry, where bar.com is the domain name of the domain you want to forward, and test.com is the domain name of the address you want mail forwarded to.

R$* < @ bar . com . >   $#smtp $@ test.com $: $1 < @ bar.com >

When you're finished, you should have an entry that looks similar to the following:

# handle numeric address spec
R$* < @ bar . com . >   $#smtp $@ test.com $: $1 < @ bar.com >
R$* < @ [ $+ ] > $*     $: $>98 $1 < @ [ $2 ] > $3
R$* < @ [ $+ ] > $*     $#smtp $@ [$2] $: $1 < @ [$2] > $3

This entry will result in all mail with the domain bar.com being forwarded to the domain test.com with an address of user@bar.com (user is the username of the person the mail is intended for). Make sure that test.com is configured to accept mail for the domain bar.com.

If for some reason the forwarded mail needs a different address (other than bar.com) substitute that address in the line so it looks similar to the following example:

R$* < @ bar . com . >   $#smtp $@ test.com $: $1 < @ test.com >

This would forward all mail addressed to bar.com to test.com with the address user@test.com.

You must kill and restart the sendmail daemon in order for the above changes to take effect.

See also

sendmail(ADMN), mail(C)

From the Xinuos technical article database, record 105404. Reproduced with permission. The original is at www.sco.com/ta/105404, which is reachable but blocked from search engines. Xinuos marks this article against a retired product line. That refers to the product’s lifecycle, not to whether the advice still works — plenty of it still applies to running systems.

Next step

Need this fixed rather than explained?

Tell us the release, what the system runs and what it is doing. We will reply by email with what we would do next.

  • You deal with the people who do the work
  • No obligation, and no upgrade required before we will help
  • We tell you plainly if something is not worth doing

Send an enquiry

We reply by email. If a server is down, say so in the first line. You can also write to help@scoexpert.com.