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)
The printable version is no longer supported and may have rendering errors. Please update your browser bookmarks and please use the default browser print function instead.

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

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.

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 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

Configuration

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

/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 ##
virtual_mailbox_domains = example.net
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/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