Postfix from scratch – episode 2 – mail delivery

In previous blog entry, we have seen that postfix (on debian systems) can be installed with an empty (but existent) configuration file. This is only possible because all values have defaults. postconf (called with no arguments) is a tool to display all postfix configuration variables. Try it !

We will be using postconf to set values directly in the /etc/postfix/main.cf

Mail delivery

We will need now to give postfix a clue to which mail we'll want him to deliver localy. This is quite simple:

# postconf -e "mydestination = wiz.orgx, home.foo.comx"
# postfix reload

Now lets see how postfix reacts to the sending of mail towards wiz.orgx:

# nc localhost 25
220 myhostname.localdomain ESMTP Postfix
MAIL FROM:<gbush@us.comx>
250 2.1.0 Ok
RCPT TO:<bugsbunny@wiz.orgx>
550 5.1.1 <bugsbunny@wiz.orgx>: Recipient address rejected: User unknown in local recipient table
^C
#

As user "bugsbunny" does not exist, postfix refuses to send the mail. To continue this, let's suppose you know how to create a new user on your system called 'john' in this example. Now lets try to send a mail to john:

# nc localhost 25
220 myhostname.localdomain ESMTP Postfix
MAIL FROM:<gbush@us.comx>
250 2.1.0 Ok
RCPT TO:<john@wiz.orgx>
DATA
354 End data with <CR><LF>.<CR><LF>
Subject: hello friend

how are you ?
.
250 2.0.0 Ok: queued as 94B822AC246
QUIT
221 2.0.0 Bye
#

Note that the domain "wiz.orgx" is not a valid domain name currently. But this will work with exactly this domain. Postfix does not do any check (and this is normal), neither of your real network domain nor of ICANN legislation. No check at all are performed on the sender's mail address neither.

But where's our mail ?

Let's check where has been put our mail: /var/mail or /var/spool/mail (which should be the same as the second is a link towards the first):

# cat /var/spool/mail/john
From gbush@us.comx  Wed Mar 24 08:04:04 2010
Return-Path: <gbush@us.comx>
X-Original-To: john@wiz.orgx
Delivered-To: john@wiz.orgx
Received: from myhostname.mylocaldomain (myhostname.mylocaldomain [127.0.0.1])
    by myhostname.localdomain (Postfix) with SMTP id CD0CC2AC246
    for <john@wiz.orgx>; Wed, 24 Mar 2010 08:03:16 +0100 (CET)
Subject: my friend
Message-Id: <20100324070339.CD0CC2AC246@myhostname.localdomain>
Date: Wed, 24 Mar 2010 08:03:16 +0100 (CET)
From: gbush@us.comx
To: undisclosed-recipients:;

how are you ?

You should notice that several information have been set in the header of the mail and that our header as been kept intact (it contained only a Subject field).

You can choose to put this file in the home directory of the user by configuring 'home_mailbox':

# postconf -e home_mailbox=MyMailBox

Mail will then be created directly in ~john/MyMailBox as a file in mbox format, or you can choose to put:

# postconf -e home_mailbox=MyMailBox/

Notice the ending slash, this will tell postfix to store mail in ~john/MyMailBox as a directory in Maildir format.

Let's choose the maildir format:

# postconf -e home_mailbox=.mail/

In further blog entry, I'll describe how to plugin procmail as a mail delivery agent.