How to make sendmail to relay local mails?

This is cited from http://www.tipstrs.com/tip/13296/Setting-up-sendmail-with-a-catch-all-for-unknown-email-addresses


If you're running sendmail on a Linux server, it's quite easy to configure sendmail so that any email sent to an unknown email address in your domain is forwarded to a known address. Doing this results in getting a bunch more spam, but I like this cause I can then use email addresses that don't exist for specific purposes (such as when a forum requires a valid email address as part of the sign-up confirmation process).

Here's how to set up an catch-all for all unknown email addresses in Fedora (your disto may be slightly different), all of these commands need to be run under the root user:

  1. Edit the /etc/mail/sendmail.mc file and look for the line that contains virtusertable in it and make sure it is not commented out. If it is commented out, remove the comment. In my case, it looks like this:

    FEATURE(`virtusertable', `hash -o /etc/mail/virtusertable.db')dn
    
  2. Edit the /etc/mail/virtusertable file and add lines like the following, one for each domain on your server that you want to add a catch-all for:

    @domain1.com postmaster-domain1
    @domain2.com postmaster-domain2
    

    In this example, any mail sent to an unknown user at domain1.com will be forwarded to the postmaster-domain1 user, and any email sent to an unknown user at domain2.com will be forwarded to the postmaster-domain2 user. For this to work, the users to whom the mail is being forwarded must exist, and be able to receive mail.

  3. From the /etc/mail directory, run the make command.
  4. Restart the sendmail service using the service sendmail restart command.

That's all there is to it. Once you take this few simple steps you wil l have a catch-all for any email sent to unknown users in your domain.