Welcome to the most active Linux Forum on the web.
Go Back > Forums > Linux Forums > Linux - Server
User Name
Linux - Server This forum is for the discussion of Linux Software used in a server related context.


  Search this Thread
Old 08-16-2006, 09:11 PM   #1
Registered: Aug 2006
Location: Mississauga, Ontario, Canada
Distribution: RHEL 5, CentOS 5
Posts: 64

Rep: Reputation: 15
Multiple domains for Postfix

Hi everyone,

Another question. Say I have and and want to setup postfix to accept and send mail for both those domains. Both domains have the same ip address by the way. Do I have to create a virtual domain? I currently have setup correctly and everything is working fine. Now I want to create a new user who has, is this possible? Are there any good tutorials on how to do this?

Old 08-17-2006, 04:03 AM   #2
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,417

Rep: Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976
normally you'd just use the virtual_alias_domains variable to the additional domains you want. that would then deliver to the same destination as if you need to be more specific than that you'd be looking ath a virtual_alias_map file.
Old 08-17-2006, 11:55 AM   #3
Child of Wonder
Registered: Jul 2004
Location: Sioux Falls, SD
Distribution: Debian, Ubuntu, Fedora, Red Hat
Posts: 69

Rep: Reputation: 16
Virtual alias domains works OK if you want all your email going to local user mailboxes. That means and are each going to have different Linux user accounts since they both can't have user1. This can be confusing to users and is harder to manage.

If you want each and account to have it's own mailbox but not a Linux user account, you need virtual mailboxes. This is how I do it on my Ubuntu Postfix box at home.

**Make sure to back up your config files before making any changes!**

First make sure Postfix has the virtual module available to use. Look for the virtual line in /etc/postfix/ If it's there (which it should) continue.

Create an account that will have access to the virtual mailboxes directory and one for each domain to write to them.

useradd vuser -u 2000  (or any uid you want above 1000)
groupadd vuser -g 2000  (same as uid)
useradd xdomain -u 2001  
groupadd xdomain -g 2001  
useradd ydomain -u 2002
groupadd ydomain -g 2002
Then create the base directory for your virtual mailboxes.

mkdir /var/spool/virtual_mailboxes
chown vuser:vuser /var/spool/virtual_mailboxes
chmod 755 /var/spool/virtual_mailboxes
Next, create the subdirectories.

mkdir /var/spool/virtual_mailboxes/
mkdir /var/spool/virtual_mailboxes/
chown xdomain /var/spool/virtual_mailboxes/
chown ydomain /var/spool/virtual_mailboxes/
chgrp xdomain /var/spool/virtual_mailboxes/
chgrp ydomain /var/spool/virtual_mailboxes/
chmod 700 /var/spool/virtual_mailboxes/
chmod 700 /var/spool/virtual_mailboxes/
Next you need to build a file that you can enter all your email addresses into. Call it /etc/postfix/virtual_build_map_source.

Code:             2001    2001             2001    2001             2002    2002             2002    2002
Then create a script to take that virtual_build_map_source file and create all the other needed files that Postfix will need. Call it /etc/postfix/

# !/bin/bash
# Build all virtual mailbox maps from one source

# section: paths

# section: build
# build $virtual_mailbox_maps
$AWK '{printf("%s %s\n",$1,$2)}' $SOURCE > $VMAP

# build $virtual_uid_maps
$AWK '{printf("%s %s\n",$1,$3)}' $SOURCE > $VUID

# build $virtual_gid_maps
$AWK '{printf("%s %s\n",$1,$4)}' $SOURCE > $VGID
Make the file executable.

chmod 755 /etc/postfix/
Then run the script and it will create the virtual_uid_map, virtual_gid_map, virtual_mailbox_recipients files and postmap them. You should also create a virtual_aliases file for any aliases you want set up. The aliases format is simple. Just write the incoming address, a space, and what address you want it to go to. Then postmap it.

Go into and add the following lines:

## Virtual Mailboxes
virtual_mailbox_domains =,
virtual_uid_maps = hash:/etc/postfix/virtual_uid_map
virtual_gid_maps = hash:/etc/postfix/virtual_gid_map
virtual_mailbox_base = /var/spool/virtual_mailboxes
virtual_mailbox_maps = hash:/etc/postfix/virtual_mailbox_recipients
virtual_alias_maps = hash:/etc/postfix/virtual_aliases

Postfix will now start delivering all incoming mail to those virtual mailboxes. The next step would be to set up your POP3 or IMAP server to allow users to get those emails. I use dovecot-pop3 and dovecot-imap.


base_dir = /var/run/dovecot/
protocols = imap pop3
log_path = /var/log/dovecot
info_log_path = /var/log/
login_dir = /var/run/dovecot/login
login_chroot = yes
login_user = dovecot
protocol imap {
  login_executable = /usr/lib/dovecot/imap-login
  mail_executable = /usr/lib/dovecot/imap
protocol pop3 {
   login_executable = /usr/lib/dovecot/pop3-login
   mail_executable = /usr/lib/dovecot/pop3
   pop3_uidl_format =  %08Xu%08Xv
valid_chroot_dirs = /var/spool/virtual_mailboxes
default_mail_env = maildir:/var/spool/virtual_mailboxes/%d/%n
disable_plaintext_auth = no
auth default {
   mechanisms = plain digest-md5
   userdb passwd-file {
      args = /etc/dovecot/users
   passdb passwd-file {
     args = /etc/dovecot/passwd
auth_executable = /usr/lib/dovecot/dovecot-auth
auth_user = root
auth_verbose = yes
Create /etc/dovecot/users and include all your users in there in the following format:

Make the file only usable by root and readable by root group.

chmod 740 /etc/dovecot/users
Create the following script and put it into /usr/sbin/mkdovecotpasswd.

mkpasswd --hash=md5 $2  > /tmp/hash
echo "$1:`cat /tmp/hash`" >> /etc/dovecot/passwd
Make it executable.

chmod 755 /usr/sbin/mkdovecotpasswd
Make your Dovecot password file and give it only root rights.

touch /etc/dovecot/passwd
chmod 740 /etc/dovecot/passwd
Now you need to assign passwords for your users. Run your new script in this format:

mkdovecotpasswd password
Do this for every user you have. If you ever need to change a password, just delete the corresponding line in /etc/dovecot/passwd and run the command again with the new password.

To add a new user, add them to the /etc/virtual_build_map_source file, run /etc/postfix/, add them to /etc/dovecot/users, and run the mkdovecotpasswd command to assign them a password. All your users can now retrieve mail via POP3 and IMAP (assuming your box is set to accept ports 110, 143, and 25 and/or have them forwarded from your router to your server) and users will be using their full email address as their username.

Restart Postfix and dovecot and you should be good.

Last edited by Child of Wonder; 08-17-2006 at 12:11 PM.
Old 12-12-2006, 01:06 AM   #4
LQ Newbie
Registered: Dec 2006
Posts: 1

Rep: Reputation: 0
One small detail....

Thanks for the detailed reply. It was invaluable.

Just one little detail:

I followed these steps to the letter and found that my postfix server was bouncing email to valid virtual user accounts. A bit of research determined that the problem was that I hadn't included the 'virtual_transport = virtual' parameter in /etc/postfix/

After adding that, everything worked fine.

P.S. I was inspired by your script, and re-wrote the whole thing in perl and in a somewhat more comprehensive format. I'll post it here as soon as I have the pod documentation completed.....
Old 12-12-2006, 01:26 AM   #5
Registered: Jun 2004
Location: Metro Manila, Philippines
Distribution: OpenBSD, Slackware, XP
Posts: 347

Rep: Reputation: 31
This one, if you are interested on trying, it uses MySQL in setting virtual domains/hosting. This is the tutorial I followed and my Slack-based postfix server based on.

Old 12-12-2006, 10:37 AM   #6
Child of Wonder
Registered: Jul 2004
Location: Sioux Falls, SD
Distribution: Debian, Ubuntu, Fedora, Red Hat
Posts: 69

Rep: Reputation: 16
I'm glad I could help. I got most of my info from "The Book of Postfix" by Ralf Hildebrandt and Patrick Koetter. AWESOME BOOK!

My next task is to set up Postfix and LDAP. We have it running where I work but I'd like to try it on my own.


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
How to make postfix accept mail from multiple domains Farthom Linux - Newbie 4 09-14-2006 12:13 PM
Postfix - how do hosted domains download their mail from my postfix franschoek Linux - Software 1 04-01-2006 10:41 PM
Postfix multiple domains & mailboxes fatum112 Linux - Software 0 11-21-2005 02:13 PM
managing different domains with postfix jules_fraser Linux - Networking 1 12-23-2003 12:07 AM
Postfix and multiple domains MasterC Linux - Networking 4 07-16-2003 02:19 PM > Forums > Linux Forums > Linux - Server

All times are GMT -5. The time now is 10:26 PM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration