Sendmail - Several local domains delivering to 1 local domain - alias vs. virtusertable

Let's say I own the domains,,,,, and

Let's also say that our internal networks are listed as Z.local in the internal DNS. Let's also assume that the DNS is perfect... it's not 100% in real life, but the only issues I have are with my ISP and reverse lookups (doesn't affect the mail).

Now, adding to our scenario, let's say that all 6 domains work on the same server. (I just have LOCAL_DOMAIN done for each domain name inside of the file). The local domain also works by way of the MASQUERADE_AS(

Now for the fun part. I want to ease the setup involved in adding a user. I use FireTrust's MailWasher server instead of spamassassin because I have to deal with end users who know nothing... they see a button they click it. Thus, I have my mailwasher setup and I have listed the local email address as the main address for each user. Then I added ALL 6 DOMAINS into the list of additional email addresses for each user in MailWasher. THEN, because each of the domains is for a different division in the company (I work in the corporate office, so I have to support essentially 6 different businesses on 1 server... can we say stupid!) anyway... since all 6 domains represent a different division of the company and users are constantly shifting from one company to another to follow a particular project, I have to constantly juggle the domain names/email address combinations to ensure that email comes and goes to an email address at the right domain.

To make it worse, I'm required to setup individual email accounts in thunderbird for each domain... the users want to be able to send under the domain for which they are working at that time.

Sound complicated enough?!? Well that isn't important. What I am looking to do is either put the 6 domains under some virtual domain type setup or possibly under the alias file (is it legal?) so that all users have ONE (1) email address.... their local address. So when an email is received it is brought in and altered so that mailwasher sees the local address, not the particular domain name that was sent to. Also, when an email is sent out, all I have to do is tell the user to select the proper account under thunderbird... even though ALL accounts under thunderbird will be pulling from the local account - they would be separated by what email domain was used for sending.

Hopefully this makes sense.  I've already gotten it to work by removing the LOCAL_DOMAIN macros and putting in the virtual domain file macros - and the virual domain file contains a line for each of domains. Then, the only local domain left is the Z.local. But the email comes through as it did before... yous end to, the user's local account receives an email with the headers saying instead of user@Z.local. If I send to, I want to see the header say but instead I see

I'm gonna add more detail to this question in case it isn't clear. If you have an alias called "alien" that is an alias for "dude" then you can send email to and it will be delivered to "". The maillog even states "alien is an alias for dude." I want to do the same thing for the DOMAIN side of the (at) symbol. I want to make an alias for called "". That way in the maillog I will see " is an alias for" and when I read the header I will see the email was sent to instead of seeing the

I guess I really just want to  do to the recipient email address what a router does to an IP packet during NAT translation. I want to see if sendmail can literally alter the header so that the email even goes to the mailwasher milter as the local domain account.

Hopefully that isn't too confusing and I've given enough info. I'm not including my because as it is right now, it is nothing like I want it to be! So clean slate. Is this sort of "translation" possible... and if so, how do I do it?
Who is Participating?
JAMason1182Connect With a Mentor Author Commented:
(continued from previously)
So now... 2 scendarios.
 1) Someone wants to send mail to Jim Bob and they send to,,,, or => The domaintable maps all the entries to entries and the normal alias file translates jim_bob, jbob, and jim.bob to just jbob (the local username). Bingo.

Similarly if someone wants to send mail to Joe Dunn, they can send to,, or joe_dunn or joe.dunn at any of those three .coms.

2) But what about joe dunn!? What if he sets up his own IMAP account that will make a connection to the mail server to send mail out and he puts his email ass Number one, joe_dunn, though in the alias file... isn't an alias in the FROM address! So assuming he passes the AUTH part of sendmail.... his email will go out FROM right?! Nope. The genericstable lists the "reverse aliases" for joe. And the macro GENERIC_DOMAIN listings in mean that each domain listed there will be passed through to find user matches in the genericstable. So no matter which joe sends out as:,, whaterver, it will be mapped to the user sending it out.

This also works in the event an employee moves from one department to another. So if joe_dunn gets moved from the F department to the A department, all I have to do is change his genericstable entry to mapp to and ALL mail will go there. Even if he sends out as jdunn@Z.local or It will all be mapped.

This is the sort of thing I wanted. Now all I have to play with is the darn order of milters and some antivirus / antispam stuff and things are perfect!

razorwoods was the one to help me. So I'm giving you the points.

razorwoodsConnect With a Mentor Commented:
Are you doing all of this manually in Sendmail itself ?

Postfix does all the things you mentioned above and it's pretty easy to manage, even at the command line.

JAMason1182Author Commented:
so would I need to replace sendmail with postfix? or would postfix work as a sort of.... first-thing milter?
Cloud Class® Course: C++ 11 Fundamentals

This course will introduce you to C++ 11 and teach you about syntax fundamentals.

razorwoodsConnect With a Mentor Commented:
You run it on top of sendmail.  If you're on Debian its as easy as ' apt-get install postfix ' and if you're on CentOS , Fidora, or RedHat it's ' yum install postfix '

You'll want to read the docs first just to be sure it's what you want.

JAMason1182Author Commented:
what is going to be involved in adding postfix on top... meaning can we get into specifics of how to get this behavior setup in postfix?

JAMason1182Author Commented:
After reading a little about postfix... it sounds almost like I would be running a different type of sendmail on top of sendmail.... meaning the virtual users table described in sendmail is pretty synonomous to the postfix documentation.... so why would I need to add postfix if sendmail can handle it? ...not shooting you down, but rather wanting to make sure it is the right move.
razorwoodsConnect With a Mentor Commented:
Sendmail will do that things you're trying to do, but from reading your question it seemed like you wanted to do the sames thing in an easier way.  Postfix is much easier to manage virtual users and alias domains in my opinion.

Lay that up with procmail for some per user recipes on mail handling ... that's an option.

JAMason1182Author Commented:
OK... will procmail do it before or after the mail filters are run? Can I get procmail to do it's recipe before the mailwasher milter gets the email? That's where the major simplification is. If I can make it so that all the "alias" domains are changed to the local domain before mailwasher does its scan, then I don't have to add all the domains to every user! It also will give me the framework for our alias scheme... (try doing all 6 domains in the following formats: first.last@domain, f.last@domain,,, etc....) Yes. I agree.  That is a dumb thing to do. But the boss thinks he knows how this should be. He's the one who said "we need a domain name for each company, you we need to make sure that all emails are sent from the proper domain name... blah blah"....

Oh wait, I digress.. so back to this. Can I get procmail to do its thing before the mailwasher milter BUT AFTER clamav? (or before both... but I'd always rather have clamav check it before doing something with it)

razorwoodsConnect With a Mentor Commented:
I believe the order in which anything processes is specified in the sendmail cf file isn't it ?

The more direct way to do this might just be to write a shell script that accepts a single argument such as frank.jones and then creates your user and updates virtual users with all the variations.

Then you'll have your existing (working) system and a way to easily get new users in and even may out.

JAMason1182Author Commented:
see I figured it would be something decently simple, such as "add a record for like this to the virtuserstable: %1@Z.local %1@Z.local %1@Z.local
" and then remake sendmail.

Or it would be great if it worked in the alias file altogether! (afterall... aren't the domains All considered "local?") So I guess I'm asking if there is a simple thing like that to help me out.... because the aliases are done before milters (My apache server sends "root" mail and I see the logs say "root is an alias for jamason1182" before I see the clamav, mailwasher, etc. milter output.

razorwoodsConnect With a Mentor Commented:
Again, this is why I like Postfix.  In the virtual table all domains are local as long as you put in the statement.

This would literally be your virtual user file for 3 domains and the user Jim Bob following your rough examples.

I was able to type this out in about 30 seconds.  It's very flexible.

ie.                virtual                virtual                virtual  jim-bob      jim-bob      jim-bob  jim-bob      jim-bob      jim-bob  jim-bob      jim-bob      jim-bob

JAMason1182Author Commented:
What I still don't get, is if i were to use postfix, then when would the user (your example) be just jim-bob?

I'm installing postfix right now.

How do I hook this into and do I need to start the postfix service yet? I have lots of questions... please bare with me!
JAMason1182Author Commented:
Wow... now that' I'm looking at the for postfix, I see that it configures similar to samba or clamav....

I'm seeing that I would have the same issues to configure postfix... but the configuration itself might be easier, but confusing.

Let me rephrase that last statement. I don't want to use postfix since I've already got sendmail up and running. I've been tweaking this instance of sendmail for years.  I might as well just get it tweaked the way I want and not lose all my customized settings/defines and features.

The problem isn't difficult... it's a matter of thinking. Define virtual domain vs. local domain. I define virtual as "it isn't really here... but I get mail for it." while a local domain is "It is here and only here. It is 'me'". I have 6 LOCAL domains. The reason why I ask about virtual is the description inside of virtuuserstable for sendmail... it says that I can list any host that's in class {w} or class {VirtHost} and the examples map from 1 domain to another domain. That is why I was asking about the host stuff.

So to revise the question, How best in sendmail, should I manage these 6 domains? And with that I'l talk about more of what i'm doing: is the abbreviated name for is the abbreviated name for and is it's own little domain. See the company name for one division is really long... ie "Some Company Name of CityName, Inc."... and so the boss bought "" Dummy. So I bought the name "" and people are happy with the short one. But all business cards, letterheads, etc. etc. all say the long name. Thus, I want the long one to be the "master" and the little one to be an alias for the big one.

So now that I really think about in a different light... I have four domains:,, and as well as Z.local. I want all my internal stuff to use Z.local. But I want all my external mail to go out as 1 of the 3 (A,C, or F). BUT I have two domain aliases, =>, and> So, how should I be managing these? Is what I want possible?
JAMason1182Author Commented:
Wow... that was tough. OK. Here we go:

First off what I needed wasn't really anything to do with aliases coming IN. After further investigation I needed to make a domaintable file so I could "alias" the domains to, and then from D and E to So I made a domaintable file, then put this in it:

So that brought the number of domains to worry about down to only A,C,F, and Z.local. So next, I altered my to include the following:

FEATURE(`domaintable',`hash -T<TMPF> -o /etc/mail/domaintable.db')dnl

Next, I made sure that the virtudomainstable was GONE... since my domainstable maps the B,D, and E to a "local" domain (A,C,F, and Z).

Next, i emptied out my virtual users table (virtusertable) as we didn't need it for that.

So now the kicker: I then made the genericstable file. It looks similar to this

#GENERICSTABLE FILE - kindof like a reverse alias file




# End of Genericstable file

(continued on next post)

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.