Setting up postfix with virtual domains

From Alpine Linux
Revision as of 16:04, 18 May 2009 by Mhavela (talk | contribs) (This document is only about postfix (with virtual domains) on alpine)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

Postfix on 1.9


The idea is to create a postfix config to host multiple maildomains.
I want to document both how it's set up and how it's maintained

When you are done with postfix installation you could proceed and install (depending on your needs)

  • clamav
  • gross
  • dovecot
  • Other email related applications

Have a look at Hosting_services_on_Alpine#Mail for various alternatives

Initial Setup

Burn alpine_1.9alpha10 on a CD and boot the machine.
Suggestion: Follow notes on Setting_up_a_ssh-server to be able to remotely administer this box.



apk_add postfix


We need to create a user on this system that has rights to read/write mail on you system.
Let's call this user vmail (you can choose another name if you like).
You will get prompted for a password.

adduser vmail

Now we need to know what gid/uid that user got.
Take notes on the numbers, you will need the in the upcoming configuration (in my case I got uid/gid '1001').

grep vmail /etc/passwd

This newly-created user will need permissions in the mail group.
Edit /etc/group and add vmail to the postdrop group. Se example below:


Create missing dirs

Seems we are missing /var/spool/mail and /var/mail so we need to create those

mkdir /var/spool/mail
ln -s /var/spool/mail /var/mail

Create virtual maildir

In the upcoming configuration we are going to specify /var/mail/vhosts/ as the virtual_mailbox_base so we need to create it.

mkdir /var/mail/vhosts

And we need to give permissions to our vmail user so he can read/write in this folder.

chown vmail:vmail /var/mail/vhosts


For now I just dump whatever I have. I will clean up these notes soon.


These are the variables that varies from the defaults

## These settings differers from the default config ##
soft_bounce = yes   # For testing
myhostname =
mydomain =
myorigin = $mydomain
mydestination = localhost, mail.localdomain, localhost.localdomain, localdomain   # See 'virtual_mailbox_domains' for more information
mynetworks =,
relayhost =
in_flow_delay = 1s
home_mailbox = Maildir/
mail_spool_directory = /var/spool/mail
smtpd_banner = $myhostname ESMTP $mail_name ($mail_version)

## The following is added to the config ##
virtual_mailbox_domains =
virtual_mailbox_base = /var/mail/vhosts
virtual_mailbox_maps = hash:/etc/postfix/vmailbox
virtual_minimum_uid = 100
virtual_uid_maps = static:1001
virtual_gid_maps = static:1001
virtual_alias_maps = hash:/etc/postfix/valias


/etc/postfix/vmailbox  #everyone else doesn't match rule above

Create DB's

Once you created the above config-files, you need to make generate some DB's

postmap /etc/postfix/vmailbox
postmap /etc/postfix/valias

I am not 100% if the next command is needed, but I think that you need to create the 'aliases' DB.

postmap /etc/postfix/aliases

Start postfix

It's time to start. Hopefully it works!

/etc/init.d/postfix start


In case something goes wrong you should have a look in your syslog.
Personally I use to tail the logfile while debugging

tail -f /var/log/messages