Postfix

Preamble

You probably don't Postfix. If you're not planning on hosting your own SMTP server (e.g. you use Google's servers), then you definitely don't need it.

To send out emails with your php scripts, sendmail (installed by default) will suffice.

Installation

I have installed Postfix:

I will do the following:
[install: postfix 2:2.0.18-4.i386]
Is this ok [y/N]: y
Downloading Packages
Getting postfix-2.0.18-4.i386.rpm
postfix-2.0.18-4.i386.rpm 100% |=========================| 2.2 MB    00:00
Running test transaction:
Test transaction complete, Success!
postfix 100 % done 1/1
Installed:  postfix 2:2.0.18-4.i386
Transaction(s) Complete

Postfix is a mail server which works particularly well in combination with Webmin. Also, according to the Webmin documentation, it outwardly behaves just like Sendmail (the standard unix/linux mail service, which is used by popular scripting languages such as php).

Starting and stopping Postfix

[root@1038 /]# /etc/rc.d/init.d/postfix -h
Usage: postfix {start|stop|restart|reload|abort|flush|check|status|condrestart}

Configuring Postfix

While looking at the Webmin For module Postfix Configuration, I found out that the files mentioned as Postfix commands in Webmin:

/usr/bin/mailq
/usr/bin/newaliases

do not exist on my system. I do not know whether this might cause any problems.

For configuration, I used the Virtualmin documentation. I have set

Postfix > Local delivery > Spool directory to /home/mail (was /var/mail )

Postfix:Virtual Domains > Domain mapping lookup tables to hash:/etc/postfix/virtual

I have also created a symbolic link:

[root@1038 /]# ln -s /home/mail /var/spool/mail

(where /home/mail is the target and mail the link name).

Update 20041222

I have replaced:

/usr/bin/mailq
/usr/bin/newaliases

with:

/usr/bin/mailq.postfix
/usr/bin/newaliases.postfix

But I still cannot get Postfix to work. So, I have completely removed and subsequently reinstalled Postfix (and the Webmin module for Postfix).

Installing and Configuring Postfix

1. Make sure that no other mail server is running on your system:

[root@1038 root]# netstat -a | grep smtp

This should not yield any output. Once you've got Postfix running, you should see this:

[root@1038 root]# netstat -a | grep smtp
tcp        0      0 *:smtp                  *:*                     LISTEN
tcp        0      0 *:smtp                  *:*                     LISTEN
unix  2      [ ACC ]     STREAM     LISTENING     53822  private/smtp
unix  2      [ ACC ]     STREAM     LISTENING     53870  private/bsmtp

2. Make sure that you have installed Postfix correctly:

[root@1038 root]# postfix check
[root@1038 root]# postconf mail_version
mail_version = 2.0.18

The first command does not return any output if everything is all right. This can be a little confusing, so to be sure we also issue the command postconf mail_version.

3. Now, first and foremost, for testing purposes, make sure that all errors get sent to you, the postmaster. Postfix will do this by default, but you still have to specify a working e-mail address (preferably outside of the domains that you will be providing e-mail services for using Postfix; in other words: use a hotmail address or some such address).

You do this in: Webmin > Postfix Configuration > Mail Aliases

Find the entry for root, and fill in your e-mail address (use the select box called “alias to” and opt for “E-mail address”).

4. To find out how virtual mapping works, first use real e-mail addresses in the “Maps to” fields (Webmin > Postfix Configuration > Virtual Domains).

Attention: Do you use Virtualmin to create new e-mail users for your virtual domains? Virtualmin adds an entry for each to the virtual domains mapping table of Postfix (etc/postfix/virtual), without specifying the local domain!

For instance, using Virtualmin to add user John to the domain fruit.com, Virtualmin creates the following entry:

john@fruit.com	fruit_john

Apparently, Virtualmin assumes that the local host and the virtual domain are the same. I have not figured out yet how to tell Virtualmin to use a different local host.

In my case, the entry should be:

john@fruit.com	fruit_john@1038.flexservers.com

WARNING DO NOT FORGET: Having Postfix Respond to Your Domain

If you just specify your email address and corresponding local user in the virtual file, Postfix will reject all outside emails to this address: Relay Access Denied. You have to tell Postfix that all mail for specific domains is to be delivered locally. You do this by making a special mapping in your virtual file: mydomain.com maps to mydomain.com. That's right, it seems to map onto itself.

Another way is to provide a value for the “mydomain” parameter in the etc/postfix/main.cf file:

mydomain = ourdomain.com

WARNING 2: Sending Out Mail Fails?

In /etc/postfix/main.cf, specify the following explicitly:

myhostname = my.server.com

Sendmail interface

Postfix offers a Sendmail interface, which allows you to use programs expecting the Sendmail mail server to be present.

This interface is /usr/sbin/sendmail.postfix. To get it working, you need to create a symbolic link:

[root@1038 sbin]# ln -s /usr/sbin/sendmail.postfix /usr/sbin/sendmail
[root@1038 sbin]# ls -l sendmail*
lrwxrwxrwx  1 root root     26 Jan 14 11:07 sendmail -> /usr/sbin/sendmail.postfix
-rwxr-xr-x  2 root root 101048 Mar 31  2004 sendmail_backup
-rwxr-xr-x  2 root root 101048 Mar 31  2004 sendmail.postfix

Without this symbolic link, your mail forms will NOT work!

In the newer Postfix versions, this seems no longer necessary as Postfix will install its own /usr/sbin/sendmail file.

Forwarding emails using the .forward file

You can place a .forward file in a user's home dir (i.e. in the same directory where the Mailbox file is). This file does not need to be translated using postmap!

The .forward file must belong to the same user (and presumably usergroup) as the Mailbox file. If it does not, then forwarding will not work.

This is what the .forward file may look like:

johndoe@gmail.com, \solin_johndoe

Here, all incoming email is forwarded (redirected) to johndoe@gmail.com as well as to the local user solin_johndoe.

On my particular system, I also had to add the domain to the local user:

johndoe@gmail.com, \solin_johndoe@mydomain.com

Otherwise, the mailserver would return the mail saying that solin_johndoe@solin.nl does not exist in the virtual alias table.

SpamAssassin

SpamAssassin classifies mail as spam (or non-spam) based on a set of rules. Installing and configuring SpamAssassin is not very hard. It is explained here:

http://advosys.ca/papers/postfix-filtering.html

If you want your email filtered by SpamAssassin, add your email domain to: /etc/postfix/filtered_domains (or create the file if it does not exist yet). This is what the file should look like:

# Filter only mail addressed to local domains:
example.com       FILTER filter:dummy
example.net       FILTER filter:dummy
otherdomain.ca    FILTER filter:dummy

Save the file and use command postmap filtered_domains to create the corresponding data file.

Dovecot

What is Dovecot?

Dovecot is an IMAP/POP3 server which supports “unix user-based” email. This means that you can just add a unix user (by using the command useradd) and Dovecot will “see” the user's mailbox. You can easily test this if you have a working mailserver:

  1. Create a new unix user: useradd tester2
  2. Assign a password:
[root@1038 tester2]# passwd tester2
Changing password for user tester2.
New UNIX password:
BAD PASSWORD: it is based on a dictionary word
Retype new UNIX password:
passwd: all authentication tokens updated successfully.
  1. Now start your email client (e.g. Thunderbird) and create a new account. Use any mailserver on the system where you created the new user, e.g. mail.yourdomain.com. Enter a fake email address (our new user “tester2” doesn't really have one, after all).
  2. Provide the email client with the login name “tester2” and whatever password you created.
  3. Copy a real mailbox to the new user's mailbox:
[root@1038 tester2]# cp /home/yourcompany/homes/some_other_user/Mailbox .
cp: overwrite `./Mailbox'? Y
  1. Hit the “get mail” button, and see what Dovecot's doing for you in the background!

Note: if we would really like to link the new user to an actual email address, we need to mention the user in Postfix's virtual domains mapping table:

- declare the mapping in the file /etc/postfix/virtual:

tester_alias@yourdomain.com solin_tester3

or:

tester_alias@yourdomain.com solin_tester3@system_domain.com

- then issue the command postmap /etc/postfix/virtual (untested 20060817)

Why Dovecot?

Virtualmin needs Dovecot. Virtualmin creates a real unix user for each new user added to a virtual webserver.

For instance, adding John to the virtual domain fruit, leads to the creation of:

  • john@fruit.com (john is virtual domain user)
  • fruit_john is the real unix user (resides in /etc/passwd)
  • a home directory: /home/fruit/homes/john

Virtualmin also automatically creates a mailbox for each new user (in fact, adding users to a virtual domain only makes sense if you need an additional e-mail address for somebody), [home dir]/Mailbox:

  • /home/fruit/homes/john/Mailbox

And last but not least, Dovecot is easily installed and configured (especially in comparison to Cyrus, which is a virtual user IMAP/POP3 server and hence incompatible with Virtualmin).

Installing Dovecot

I will do the following:
[install: dovecot 0.99.10.5-0.FC2.i386]
Is this ok [y/N]: y
Downloading Packages
Running test transaction:
Test transaction complete, Success!
dovecot 100 % done 1/1
Installed:  dovecot 0.99.10.5-0.FC2.i386
Transaction(s) Complete

Starting Dovecot

[root@1038 etc]# /etc/rc.d/init.d/dovecot -h
Usage: /etc/rc.d/init.d/dovecot {condrestart|start|stop|restart|reload|status}

Configuring Dovecot

Dovecot can be (almost entirely) configured through /etc/dovecot.conf. By default, pop3 is not enabled. So I had to enable pop3 (many older e-mail clients still support only pop3):

protocols = imap imaps pop3 pop3s

I also had to tell Dovecot where to find the users' e-mail boxes:

default_mail_env = mbox:/%h/:INBOX=/%h/Mailbox

What does this mean?

INBOX: path to mailbox file

mbox: path to other directories which Dovecot may need to store additional information for this particular e-mail user (pop3 only needs one file, but Dovecot is mainly built around IMAP)

The %h variable contains the (path to the) user's home directory (as found in /etc/passwd).


Personal Tools