Setting up postfix with virtual domains
Postfix on 1.9
General
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 and instructions.
Initial Setup
Burn alpine-1.9.3-x86.iso (or higher) on a CD and boot the machine.
Suggestion: Follow notes on Setting_up_a_ssh-server to be able to remotely administer this box.
Postfix
Install
apk_add postfix
Prepare
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:
postdrop:x:208:vmail
Create missing dirs
Seems we are missing /var/spool/mail so we need to create it
mkdir /var/spool/mail
Create virtual maildir
In the upcoming configuration we are going to specify /var/spool/mail/vhosts/ as the virtual_mailbox_base so we need to create it.
mkdir /var/spool/mail/vhosts
And we need to give permissions to our vmail user so he can read/write in this folder.
chown vmail:postdrop /var/spool/mail/vhosts
Configuration
FIXME: The following configuration needs some more work
/etc/postfix/main.cf
These are the variables that varies from the defaults
## These settings differers from the default config ## soft_bounce = yes # For testing myhostname = mail.example.net mydomain = example.net myorigin = $mydomain mydestination = localhost, mail.localdomain, localhost.localdomain, localdomain # See 'virtual_mailbox_domains' for more information mynetworks = 192.168.10.0/24, 127.0.0.0/8 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 ## local_transport = virtual virtual_mailbox_domains = example.net virtual_mailbox_base = /var/spool/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 smtpd_helo_required = yes disable_vrfy_command = yes smtpd_recipient_restrictions = reject_unauth_pipelining, permit_sasl_authenticated, permit_mynetworks, reject_invalid_hostname, reject_non_fqdn_hostname, reject_non_fqdn_sender, reject_non_fqdn_recipient, reject_unknown_sender_domain, reject_unknown_recipient_domain, reject_unauth_destination, permit smtpd_data_restrictions = reject_unauth_pipelining, permit
/etc/postfix/valias
postmaster@example.net user1@example.net hostmaster@example.net user2@example.net
/etc/postfix/vmailbox
user1@example.net example.net/user1/ user2@example.net example.net/user2/ @example.net example.net/catchall #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
Debugging
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
Add/Remove mailboxes
In the above examples we used /etc/postfix/vmailbox to store our list of mailboxes.
To add/remove a mailbox, you need to edit this file and then rebuild the DB.
vi /etc/postfix/vmailbox postmap /etc/postfix/vmailbox
Now we have done our re-configuration and we want postfix to start using the new settings.
postfix reload