Glenn Sidman

Updated: January 30, 2004
This HOWTO focuses on replacing Sendmail with Postfix. I also hope to offer a starting point for those interested in tinkering with an Internet accessible mailserver. If you are interested in the later, please be aware that mail is a complex thing, and requires strong security awareness. A compromised mailserver can allow others to perform very annoying and sometimes illegal activities.
The following versions were used for this HOWTO:
In the following, I will cover installing Postfix via the FreeBSD ports collection. I recommend using CVSup to update your ports prior to installing Postfix. Installation of the ports collection and CVSup are covered in my HOWTO Installing CVSup and the Ports Collection. Now lets get to it. Issue the following to locate Postfix in the Ports collection:
cd /usr/ports
make search name=postfix
Installation is quite simple. Change to the 'postfix-current'directory and make install. (Note: postfix-current is the very latest production release which is subject to change, however, it is not a beta release). Running make install will download the source files, compile, and install. Immediately after issuing "make install" you will be presented with the "Postfix configuration options" menu. (This is just an easy way of adding compile options.)
cd /usr/ports/mail/postfix-current
make install

In this example, I have selected TLS to provide support for encrypted passwords as well as SASL2 to provide an additional authentication layer capable of authenticating external connections/usres. These are not needed for this HOWTO. However, if you do add them, they will not adversely effect Posfixs functionality unless you specifically turn them on in the Postfix configuration file. Of course, from a security standpoint: Do not install stuff you will not use and maintain.
When Postfix is completing the installation, you will be asked the following questions. I chose 'yes'for both:
|           |
If you goofed and selected the default "NO" to activate Postfix in /etc/mail/mailer.conf, just manually change mailer.conf as shown below. The first, is the original mailer.conf for sendmail and the second is what the Postfix install would have created for you.
|
|           |
Groups 'maildrop'and 'postfix'added. User 'postfix'added. The following files are modified and/or added: /etc/group - CHANGED /etc/master.passwd - CHANGED /etc/spwd.db - CHANGED /etc/pwd.db - CHANGED /etc/passwd - CHANGED /etc/mail/mailer.conf - CHANGED /etc/mail/mailer.conf.old ADDED (Postfix is being polite) /usr/local/bin/pcregrep - ADDED /usr/local/bin/pcretest - ADDED /usr/local/bin/pcre-config - ADDED /usr/local/bin/newaliases - ADDED /usr/local/bin/mailq - ADDED /usr/local/bin/rmail ADDED /usr/local/sbin/postalias - ADDED /usr/local/sbin/postcat - ADDED /usr/local/sbin/postconf ADDED /usr/local/sbin/postfix - ADDED /usr/local/sbin/postkick - ADDED /usr/local/sbin/postlock - ADDED /usr/local/sbin/postlog - ADDED /usr/local/sbin/postmap - ADDED /usr/local/sbin/postsuper - ADDED /usr/local/sbin/postdrop - ADDED /usr/local/sbin/postqueue - ADDED /usr/local/sbin/sendmail ADDED |
cd /usr/local/etc/postfix
cp main.cf main.cf.ori (Make a backup of the original if not already there)
ee main.cf
I have uncommented and/or edited the following for my server:
  myhostname = mail.foo.org # our external name
  mydomain = foo.org # our external domain
  myorigin = $mydomain
  mydestination = $myhostname, $mydomain, mail.$mydomain,
            localhost.rocks.local, bsd.rocks.local, rocks.local
Note that mydestination should appear to Postfix as if it were entirely on one line. Alternatively, you may begin a second line with white-space and Postfix will interpret this as one continueses line. This is something to keep in mind if you DO NOT want Postfix to interpret two options as one continues line. If you have multiple interfaces and do not desire an SMTP Internet presence, you should also look at mynetworks. Adding notify_classes for everything, as shown below, may be helpful for trouble shooting. Again, please look at the config file comments for each change.
  notify_classes = resource, software, bounce, 2bounce, delay, policy, protocol
In order to receive messages, such as the notify_classes messages, from Postfix (more specifically, the postfix user), you will need to configure an alias. The simplest is to add a postfix to root alias. You will then receive postfix messages to your root mail account. However, as most aliases point to root, you may want to aliase the postfix user to root and then alias root to your mail account. Confused? Both methods are explained below. If you have never configured aliases, you may want to read the /etc/aliases fileits a quick read.
ee /etc/aliases (FYI: this is actually a link to /etc/mail/aliases)
If not already there, add the following line:
postfix: root
Add the following if you wish to forward all of roots mail to your account:
root: you@your.domain (I believe there is a sample in the aliases file)
After editing /ect/aliases you will need to run 'newaliases'. This will update /etc/aliases.db.
newaliases [I hope to add some assistance with DNS configuration here.]
ps -x | grep sendmail
    123   ?         sendmail (This is the output)
Now kill process 123 with:
kill 123 This should kill Sendmail. Now check Postfix with the following command:
postfix check (no output is good output)
Now start postfix with the following command:
postfix start Postfix is now running (hopefully). You can verify a happy SMTP daemon by any of the following:
netstat an (look for a listening TCP 25 port)
ps x | grep postfix
telnet localhost 25
When you telnet to localhost 25, you should receive: "220 [your host name] ESMTP Postfix" Notice that [your host name] matches the 'myhostname'value in your main.cf file. This is the name your name servers MX record should point to.
|           |
If you have postfix configured in your /etc/mail/mailer.conf (answered yes to
the previous question) and would like to enable postfix to start at boot time,
please set these variables in your /etc/rc.conf file:
sendmail_enable="YES" This will disable Sendmail completely. Alternatively to the above settings, you can enable postfix to start with the other local services, for example, after your database server starts if you need it to be running for postfix. To do this, set in your rc.conf file:
sendmail_enable="NONE" Then make the following symbolic link:
cd /usr/local/etc/rc.d Also, you will want to disable some Sendmail-specific daily maintenance routines in your /etc/periodic.conf file:
daily_clean_hoststat_enable="NO" If you are using SASL, you need to make sure that postfix has access to read the sasldb file. This is accomplished by adding postfix to group mail and making the /usr/local/etc/sasldb* file(s) readable by group mail (this should be the default for new installs). If you are upgrading from postfix version prior to 2.0, please see the README files for recommended changes to your configuration. |
Alas, we have options. I have chosen the second method as someday I may prefer that Postfix not start before a database server. By that time, I will likely have forgotten how to do this. For the second option, make the following changes to rc.conf. For the first option, you are on your own.
cp /etc/rc.conf /etc/rc.conf.ori (backup for goof-ups)
ee /etc/rc.conf
Change sendmail_enable = "YES" to sendmail_enable = "NONE"
|           |
  YES = Enable Sendmail   NO = Sendmail still starts! Sendmail stops accepting connections from other system, but still runs for localhost mail services.   NONE = Disable Sendmail completely |
FreeBSD runs scripts in /usr/local/etc/rc.d on boot. In this case we are just creating a symbolic link rather than a script. (Newbe Note: Symbolic link = Shortcut in Windows.)
cd /usr/local/etc/rc.d
ln -s /usr/local/sbin/postfix postfix.sh
If you have a 'periodic.conf'file, make the changes recommended above in the pkg-message, otherwise this doesnt appear to be needed.
If you are interested in connecting and retrieving mail from your new mail server with a POP3 client, you will need to add a POP3 server. You can checkout my HOWTO Adding POP3 to Postfix with akpop3d if you are interested.
If you are interested in authenticating SMTP connections and allowing external clients to relay mail, (For instance, you want to send an email message through your server while you are traveling), you can checkout my HOWTO Adding SASL to Postfix. Alternatively, you can search Google for information on adding a pop-before-smtp script.
Postfix + TLS + SASL on FreeBSD by Tim Yocum :
http://yocum.org/faqs/postfix-tls-sasl.html
Glenn Sidman
