« Happy New Year! | Main | Why you should make your PostgreSQL tables without OIDs »

January 02, 2006

Sendmail Virtual User Trick

One of the things people find difficult about Sendmail is virtual users.  These are defined in the virtusertable file ( usually in /etc/mail/virtusertable ). This file instructs Sendmail to translate a "virtual" user into a real user or alias. The reason I mention aliases here is because, with Sendmail, you can have a virtual user that translates into a alias for multiple local and/or remote E-mail accounts.

A situation some people run into is that they want all usernames at domain2.com to be delivered to the same username at domain1.com, except for a few users.... If you really wanted all users to map to the other domain it would be as simple as adding the domain into the local-host-names.  It is the need to have *most* users map to the other domain where the virtusertable file comes in handy.  For this example, let's assume that we want all users names @domain1.com except for postmaster, webmaster, and support to map to the same username @domain2.com this would be accomplished by adding domain2.com to the local-host-names file to tell Sendmail that we wish to receive mail for that domain and then adding the following to the virtusertable file:

postmaster@domain2.com: mailadmin@example.com
webmaster@domain2.com: webmsater@example.com
support@domain2.com: support@example.com
@domain2.com: %1@domain1.com

The first three lines tells Sendmail to send messages sent to those three usernames at domain2.com to the appropriate remote E-mail addresses. The last line instructs sendmail to send *any* other usernames sent to domain2.com to the same username at domain1.com. Note that this will also include any fake usernames that a spammer might send to. The E-mail server at domain1.com will still be responsible for determining what is or is not a valid username. After you've added those entries to the virtusertable file all you need to do is rebuild it and it becomes active.
       

TrackBack

TrackBack URL for this entry:
http://www.typepad.com/t/trackback/2117594/7220970

Listed below are links to weblogs that reference Sendmail Virtual User Trick:

Comments

Frank,

Based on your example, I would assume that if I wanted to map only postmaster@domain1.com and abuse@domain1.com to my main domain (domain.com), then I would exclude the final line in your example so that the virtualuser table would look like:

postmaster@domain1.com postmaster@domain.com
abuse@domain1.com abuse@domain.com

I was under the impression if I defined the domain1.com to my local-host-names file, that any inbound email messages with validuseremail@domain1.com as the address would would be redirected to the main domain such as validuseremail@domain.com. Is this not a valid assumption if I use the virtualuser table with domain1.com definitions posted above?

Thanks
Steve

No you're correct. Virtual users are most useful when you are hosting multiple domains and the common users names for the domains need to go to separate users. For example, if you were hosting 20 domains and needed webmaster at each domain to go to a differnet person.

If you simply added them all to your local-host-names file then only one 'webmaster' account could exist.

The last line of the example above could be really useful if domain1.com isn't hosted on the same system as domain2.com

Thank You !

Post a comment

Comments are moderated, and will not appear on this weblog until the author has approved them.

If you have a TypeKey or TypePad account, please Sign In