I would like to know how to configure sendmail to only send emails to one domain.

I have a development server that might have customer email addresses in the database as the data is copied from the production server from time to time. I would like to make sure that the developement box (Redhat 5.3) does not send any mails externally but will send to my local users. For the sake of argument my domain is example.com and sendmail is currently set to relay mail to our SBS2008 exchange server.

So far I have not been able to find out how to do this.


Try adding this in your sendmail.mc:

R$* < $=w . > $*     $#OK
R$* < $*. > $*       $: user < @ example.com. > $3

This modifies ruleset 0 (the one that selects how email is going to be routed) as follows: If this is a local mail address (the domain part is included in $=w) then proceed as usual. Else, send email for every external address to user@example.com.

When adding the above snippet in your sendmail.mc take care to NOT copy-paste the rules, but type them. The two sides of the rules are not space separated. They are separated by tabs (at least one; two or more do not make a difference).

After editing sendmail.mc you have to produce sendmail.cf and restart sendmail. I do not know how this is done in your distribution. In Debian I run sendmailconfig.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.