Thu 11 Jan 2007
EMail - Setting up Multiple Domains
Posted by Richard under Configuration , Software , Westhost[6] Comments
or How to setup recipient@domain1.com and recipient@domain2.com to be delivered to different mailboxes
Apache provides the ability to host multiple domains on a single VPS account using Virtual Hosts. However, we run into a problem if we want email to be treated uniquely for each domain.
There are several programs involved in processing email on the server, but we won't have to change most of them. These include
| Program | Description |
|---|---|
| * If installed | |
| sendmail | used to send and receive email by your server |
| procmail | used to process email after it is received by sendmail |
| spamassassin* | called from procmail to filter out spam messages |
| clamav* | called from procmail to filter out viruses |
| qpopper | used to deliver email to your computer using the pop3 protocol |
| uw-imap* | used to view email on your computer using the imap protocol |
Sendmail uses a lookup table (virtusertable) to convert an email address into a Unix user account. Full details can be found at Sendmail's website
If you have a hosting plan which allows for multiple domains, then Westhost configures virtusertable so that email to recipient@anydomain.com is delivered to the Unix mailbox for recipient's account. We need to modify this so that the email for recipient@domain1.com is delivered to a separate mailbox from recipient@domain2.com
You will need SSH access to your server to complete this task. PuTTY is available for free for this purpose from here; configuration instructions are available from Westhost.
Here are the steps you will have to take:
Create separate user accounts
- Login in to your site manager
- Click on EMail/FTP Management (Second item on menu bar)
- Click on New E-mail/FTP button (in lower right)
- A window titled “E-mail/FTP Wizard (1 of 3)” will pop up.
-
- Enter the user details for recipient@domain1.com. Use a unique user name - I suggest recipient.domain1.com
- Click on Next once you have entered user name, description and password
- A window titled “E-mail/FTP Wizard (2 of 3)” will pop up.
-
- Modify the email quota if desired. We can change this later by editing the file /etc/features
- Enable the Autoresponder - it can be setup later by logging in to the the user account at http://www.domain1.com/users/
- A window titled “E-mail/FTP Wizard (3 of 3)” will pop up.
-
- Disable FTP access unless needed
- Repeat the above for recipient@domain2. I suggest using a user name of recipient.domain2.com
Edit virtusertable
- If you are comfortable with SSH then edit /etc/mail/virtusertable on the server or, alternatively, download a copy to your computer and edit it using a simple text editor such as Notepad (on a Windows PC). DO NOT USE A WORD PROCESSOR. Make sure you backup the file first.
- virtusertable will contain various lines, but you should find these at the end
recipient.domain1.com@domain1.com recipient.domain1.com recipient.domain1.com@domain2.com recipient.domain1.com recipient.domain2.com@domain1.com recipient.domain2.com recipient.domain2.com@domain2.com recipient.domain2.com
- Change this to
recipient@domain1.com recipient.domain1.com recipient@domain2.com recipient.domain2.com
NOTE: the two columns of data MUST be separated by a TAB
- Upload the changed file to /etc/mail/virtusertable
Create genericstable (optional)
If you want any applications or scripts on your server to send email from recipient@domain2.com, then follow these optional steps.
- Create a new file /etc/mail/genericstable which contains
recipient.domain1.com recipient@domain1.com recipient.domain2.com recipient@domain2.com
Create generics-domains (optional)
- Create a new file /etc/mail/generics-domains which contains
domain1.com domain2.com
Modify sendmail.mc (optional)
- Add these two lines to /etc/mail/sendmail.mc
FEATURE(`genericstable', `dbm /etc/mail/genericstable')dnl Added two lines GENERICS_DOMAIN_FILE(`/etc/mail/generics-domains')dnl
Activate changes
- Login to your server using SSH
- Generate a new copy of virtusertable.db by entering the command makemap hash /etc/mail/virtusertable </etc/mail/virtusertable
(If you are not hosted by Westhost, then check your /etc/mail/sendmail.cf file for the type of database used by virtusertable. This will be either hash (as above) or dbm) - If you completed the optional steps above, you will also need to
- generate a copy of genericstable.db by entering the command makemap hash /etc/mail/genericstable </etc/mail/genericstable on one line.
- regenerate your sendmail configuration file if you made the optional changes by typing m4 /etc/mail/sendmail.mc >/etc/mail/sendmail.cf (again on one line)
- Logout of your SSH session (logout)
Configure your email client
- You will need to set up two accounts
- For domain1.com
- Your Name: Recipient One
- EMail Address: recipient@domain1.com
- Incoming Mail Server: pop.domain1.com
- Outgoing Mail Server: smtp.domain1.com
- User Name: recipient.domain1.com
- Password: domain1
- NOTE: User Name and Password are case sensitive. In other words, recipient.domain1.com is not the same as Recipient.Domain1.Com
- Under More Settings:
- Click on Outgoing Server
- Select “My outgoing server requires authentication”
- Select “Use same settings as my incoming mailserver”
- For domain2.com
- Your Name: Recipient Two
- EMail Address: recipient@domain2.com
- Incoming Mail Server: pop.domain2.com
- Outgoing Mail Server: smtp.domain2.com
- User Name: recipient.domain2.com
- Password: domain2
- NOTE: User Name and Password are case sensitive. In other words, recipient.domain2.com is not the same as Recipient.Domain2.Com
- Under More Settings:
- Click on Outgoing Server
- Select “My outgoing server requires authentication”
- Select “Use same settings as my incoming mailserver”
Distribution lists
These can be created by editing /etc/mail/aliases


February 2nd, 2007 at 1:05 pm
[...] If you want email for joe@domain1.com and joe@domain2.com to be delivered to different users, then you will have to edit /etc/mail/virtusertable as described in this post or elsewhere in the Westhost forum. By default mail to joe@domain1.com and joe@domain2.com are delivered to user joe. Add this article to your bookmarks [...]
October 6th, 2007 at 9:07 am
It seems the major difference is that email setup has user = recipient.domain2.com instead of recipient+domain2.com. True?
October 6th, 2007 at 10:12 am
At top of /fm/FileManager/FileManager.cgi is “Execute a Command” which goes to Enter Shell Command:
Can this replace putty for “Activate changes * Login to your server using SSH * Generate a new copy of virtusertable.db by entering the command makemap hash /etc/mail/virtusertable
April 20th, 2009 at 7:30 am
Nice post! Now understand about this topic better and I learn a large from your other post in your blog. I’ll be waiting for another post. Thank You.
March 1st, 2010 at 6:07 am
Good Thanks
March 14th, 2010 at 6:21 pm
Hey..just want to let you know i appreciate your blog and some of your posts… well..lol..not really many ones, but i like the “idea”.. i’m a blog owner too