Secure email servers from scratch with FreeBSD 6 (Part 2)
Configuring the core components
Download the whole article as PDF
Short URL: http://fsmsh.com/1532
- 2006-12-13
- Server side | Advanced
-
Write a full post in response to this!
This content was sponsored by:
In the last article we parted ways after configuring a base FreeBSD system, enabling it with upgrades via cvsup and portsupgrade, and securing it with a simple ipfw2 firewall. The previous article created a solid foundation which this article will build on, covering the configuration of Postfix, amavisd-new, ClamAV, SpamAssassin, MySQL and finally SquirrelMail for web mail. The final setup will have all the bells and whistles of a high end-mail setup: web-mail, anti-virus filtering, spam filtering, and hosting unlimited domains with virtual domains and users stored in MySQL.
Postfix is released under the IBM Public License, and not the GNU Public License
Postfix
The first and most important component is Postfix, a well known mail transfer agent developed by Wietse Venema at IBM and initially known as the “IBM Secure Mailer”. Venema, is a respected software engineer who also developed the popular security tool “S.A.T.A.N” (Security Administrator Tool for Analyzing Networks). Postfix is released under the IBM Public License, and not the GNU Public License; the “IPL” has been approved as an open source license by both the Free Software Foundation (“FSF”) and the Open Source Initiative(“OSI”); however, it has been declared incompatible with the GPL. Initially Postfix was created in reaction to a long list of security vulnerabilities in Sendmail, the then dominant “MTA”. The direct result of the “security first” mind, Postfix has a well earned reputation for being easy to setup, fast and secure.
Postfix has two central configuration files:
main.cf: which configures the “properties” of the mail server such as where user and domain information is stored, or which domains to accept mail for.master.cf: which configures the “behavior” of the Postfix daemon, such as configuring interfaces to non Postfix programs, and other configuration settings for the Postfix daemon itself.
FreeBSD places the configuration files of packages installed from ports under /usr/local/etc; so normally you’ll find the Postfix configuration files under /usr/local/etc/postfix. First of all, you should install Postfix from the ports tree, in the same way that MySQL was installed in the first article.
Installing Postfix using ports
cd /usr/ports/mail/postfix make install && make clean
You will then be presented with a dialog box: select TLS and MYSQL.
Note that when MySQL functionality is selected, the default action is to install the MySQL 4.1 client library. If you plan on running a newer version of MySQL, such as 5.0, simply cancel the Postfix installation, install the MySQL client library of your choice, and then re-run the installation.
Example:
cd /usr/ports/databases/mysql50-client make install && make clean
During the installation of the client libraries you may be prompted for options to the gettext package. It’s not necessary to select any of the options, but feel free to do so if you wish.
After Postfix is built, you will be prompted asking if you want to activate it in the mailer.conf file: say “yes”:
[Prompt] Would you like to activate Postfix in /etc/mail/mailer.conf [n]? y
Configuring Postfix—main.cf
Now that Postfix is installed, it’s time to dive into the most important of the two configuration files, main.cf. In this one file there are essentially two sets of directives: one for the domains the server will be hosting, which being with the virtual prefix; and one for the mail server itself, with lines that begin with my as in myhostname. I’ll be giving in line commentary, so read the configuration file closely.
# These virtual_* directives configure the domains, users, # and aliases this Postfix instance will handle. # Use proxy: for performance virtual_alias_maps = proxy:mysql:/usr/local/etc/postfix/mysql_virtual_alias_maps.cf virtual_mailbox_domains = proxy:mysql:/usr/local/etc/postfix/mysql_virtual_domains_maps.cf virtual_mailbox_maps = proxy:mysql:/usr/local/etc/postfix/mysql_virtual_mailboxes_maps.cf proxy_read_maps = $local_recipient_maps $mydestination $virtual_alias_maps $virtual_alias_domains $virtual_mailbox_maps $virtual_mailbox_domains $relay_recipient_maps $relay_domains $canonical_maps $sender_canonical_maps $recipient_canonical_maps $relocated_maps $transport_maps $mynetworks $virtual_mailbox_limit_maps # Where to store the mail virtual_mailbox_base = /usr/local/virtual # Ownership of the mail directory virtual_uid_maps = static:125 virtual_gid_maps = static:125 smtpd_sasl_auth_enable = yes smtpd_sasl_local_domain = $myhostname smtpd_sasl_security_options = noanonymous # Secure SMTP-AUTH smtpd_use_tls = yes smtpd_tls_enforce_tls = yes # Uncomment the following line if you only want auth to happen over tsl # smtpd_tls_auth_only = yes # This setups the ssl certificates which I'll configure a little later smtpd_tls_cert_file = /usr/local/etc/postfix/smtpd.crt smtpd_tls_key_file = /usr/local/etc/postfix/smtpd.key # Mostly for MS outlook clients broken_sasl_auth_clients = yes # Built in restrictions smtpd_recipient_restrictions = permit_mynetworks, permit_sasl_authenticated reject_non_fqdn_hostname, reject_non_fqdn_sender, reject_non_fqdn_recipient, reject_unauth_destination, reject_unauth_pipelining, reject_invalid_hostname, reject_rbl_client opm.blitzed.org, reject_rbl_client list.dsbl.org, reject_rbl_client bl.spamcop.net, reject_rbl_client sbl-xbl.spamhaus.org # Enables virtual hosting virtual_transport = virtual # Filter with amavis-new which uses clam-av for content_filter=smtp-amavis:[127.0.0.1]:10024
Write a full post in response to this!
Similar articles
Do you like this post?
Vote for it!
Copyright information
Verbatim copying and distribution of this entire article is permitted in any medium without royalty provided this notice is preserved.
Biography
Yousef Ourabi: Yousef Ourabi is a developer in the San Francisco bay area. He is currently working at the startup he recently founded, Zero-Analog. Zero-Analog is currently developing an enterprise application, however, one of its stated goals is "to increase the rate of open source adoption in companies of all sizes, across all industries". Zero-Analog also offers consulting services, all based around open source tools, frameworks and applications.
- Login or register to post comments
- 87258 reads
- Printer friendly version (unavailable!)




Two fantastic free software companies that make Free Software Magazine possible:
Buzz authors
Free Software news
- Two More Bills in the SCO Bankruptcy and Some Trademark Oddities
- Psystar Files Motion to Leave Chapter 11
- Swiss court: Gov can buy M$ licenses, but has to be aware of risk that contracts could be declared void during main process !freesoftware
- after using the #gimp for more than 3 years for my modest needs, I start to get familiar with it ;) #freesoftware #linux
- #vim users: favourite feature? For me it's ":set paste" real time saver - !freesoftware
Similar entries
Other sites
- The Top 10 Everything (Dave). The good, the bad and the ugly.
- Free Software news (Dave & Bridget). All about free software -- free as in freedom!
- Book Reviews: Illiterarty (Bridget). Book reviews, blogs, and short stories.
Hot topics - last 60 days
-
2009: software installation in GNU/Linux is still broken -- and a path to fixing it
Tony Mobily, 2009-06-23 -
The Bizarre Cathedral - 44
Ryan Cartwright, 2009-06-08 -
Free Software Magazine caught in the 3fn shutdown crossfire
Tony Mobily, 2009-06-05 -
Is Android the key to the GNU/Linux desktop? Really?
Tony Mobily, 2009-06-12 -
The Bizarre Cathedral - 45
Ryan Cartwright, 2009-06-15
Hot topics - last 21 days
-
2009: software installation in GNU/Linux is still broken -- and a path to fixing it
Tony Mobily, 2009-06-23 -
The Bizarre Cathedral - 45
Ryan Cartwright, 2009-06-15 -
Will Google Wave revolutionise free software collaboration?
Ryan Cartwright, 2009-06-15 -
The Bizarre Cathedral - 46
Ryan Cartwright, 2009-06-22

i thing there is an error
Submitted by Anonymous visitor on Sat, 2006-12-02 14:00.
Vote!i thing there is an error in the manual.
actualy i was expecting part two with great impatience
now i am testing it and so far i am at the mysql query part
here i am:
Grant privileges
###
Run the following command:
GRANT SELECT on mail.* to mail_admin identified by password ('mail_admin_password');
###
(it is from inside of mysql)
but i get syntax error on this step
"ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '('mail_admin_password')' at line 1"
i am not a mysql specialist, but i tried some variations of that command, but still i got errors
i thing that there is something missing, i dont see where in mysql the user mail_admin is created, and may be this is the reason this command to fail.
forgive me if i am wrong, but please fix it :))
GRANT SELECT on mail.* to
Submitted by Anonymous visitor on Sat, 2006-12-02 14:13.
Vote!GRANT SELECT on mail.* to mail_admin identified by password ('mail_admin_password');
should be
GRANT SELECT on mail.* to mail_admin identified by 'mail_admin_password';
and there will be no errors :))
.pdf or printable version?
Submitted by Anonymous visitor on Tue, 2007-01-02 22:30.
Vote!Can we please have a .pdf or at least a printable version of this article?
Thanks a lot :)
printable version!!!
Submitted by Anonymous visitor on Mon, 2007-01-08 13:10.
Vote!+1 for the printable version of this article.
Suggestion & printable version
Submitted by Anonymous visitor on Tue, 2007-01-16 10:45.
Vote!+1 for the printable version also (metoo... Feh)
Also, given the FreeBSD project themselves now recommending using portsnap rather than cvsup to keep your ports tree up-to-date (and speaking personally, it's a whole lot easier to work than cvsup) might it be worth mentioning it?
viz Portsnap
Submitted by Yousef Ourabi on Thu, 2007-01-18 01:26.
Vote!The problem as I see it with portsnap is that you can't upgrade your src tree -- and seamless upgrading from release to release via make buildworld && make buildkernel is one of FreeBSD's strongest points -- and with one extra line to the cvsup config file it (cvsup) can pull down source and documents -- so it's still more attractive in my eyes
Though there are strong advantages to portsnap: faster update, no portsdb -Uu after pulling down the ports tree, more secure (signed with keys...etc)
-Yousef Ourabi
Nice Article
Submitted by Anonymous visitor on Fri, 2007-01-19 13:54.
Vote!... but what makes this mailserver secure now?
A lot of things are left out in this doc
Submitted by Anonymous visitor on Sun, 2007-01-21 07:16.
Vote!This doc is by no means even close to a beginners document. there are all kinds of steps left out and missing parts that a newbie would totally screw a system up... So tread lightly and research everything first by looking at other sources especially with the Kernel Make. Its a hopeless mess....
Draco
Anonymous
Submitted by Anonymous visitor on Sun, 2007-01-21 18:27.
Vote!Not that it's of weighing importance, but one should take notice of the error in the filename of the certificate (`main.cf', page #1 of the tutorial). It says `smtpd.cert', whilst the certificate created is named `smtpd.crt'. Naturally, one would stumble across this even at first go, but then again, it might serve well changing it if one wanted a spotless and correct version for print.
Good day to all, and thank you Yousef for your great article.:)
Fixed
Submitted by admin on Tue, 2007-01-23 02:00.
Vote!Good pick up.
Thanks
SASL daemon
Submitted by Anonymous visitor on Tue, 2007-01-23 09:43.
Vote!In a configuration like that is the saslauthd need to be started also, or it is not necessary.
I am confused because I found many posts starting the saslauthd and others not.
Is the following variables needed smtpd_sasl_application_name, smtpd_sasl_type.
maildir ... directory or file
Submitted by Anonymous visitor on Fri, 2007-01-26 05:30.
Vote!If the maildir field in the MySQL data base is a directory Postfix complains:
Jan 26 00:13:35 web postfix/virtual[1190]: 24A635C9: to=, relay=virtual, delay=0.41, delays=0.12/0.18/0/0.11, dsn=4.2.0, status=deferred (delivery failed to mailbox /usr/local/virtual/jennifer: cannot open file: Is a directory)
If the maildir field in the data base is a file IMAP complains:
Jan 26 00:17:51 web imapd-ssl: chdir jennifer: Not a directory
Any thoughts?
re: maildir
Submitted by Yousef Ourabi on Mon, 2007-01-29 10:49.
Vote!Hey:
if you do a mysql "select maildir from mailbox", do the directories have a trailing / -- if not that's probably the cause.
-Yousef
Thanks ... one more
Submitted by Anonymous visitor on Sat, 2007-02-03 23:32.
Vote!Thanks for the pointer on the maildir above. I am having some issues with squirrelmail I keep getting the following error when trying to navigate to the web page:
/libexec/ld-elf.so.1: /usr/local/lib/php/20020429/gettext.so: Undefined symbol "php_realpath"
Note I am running PHP 4, I don't know if this is related.
Thanks again,
Aaron
Looks like squirrelmail does reuire PHP5
Submitted by Anonymous visitor on Sun, 2007-02-04 18:07.
Vote!Since my web server was already running PHP4 and I didn't feel up to trying to load both modules into apache I ended up using sqwebmail. Very intuitive and simple in its configuration.
Thanks again,
Aaron
what about rc.conf?
Submitted by Anonymous visitor on Mon, 2007-02-19 17:29.
Vote!what to add in rc.conf? i mean how to start all these programs?
what about rc.conf?
Submitted by Anonymous visitor on Mon, 2007-02-19 17:22.
Vote!i was just wondering what do i have to add to rc.conf to start all of this apps... I've installed them exactly as it's guided...
thx
Help Needed
Submitted by Anonymous visitor on Sat, 2007-03-10 14:57.
Vote!Hello all - I am a complete newbie to FreeBSD and any Unix/Linux based systems. My company has been a Windows only shop until a change in management. I followed this article to the "T" and am having problems. When I start Postfix, I get an error that it cannot perform a lookup using the mysql_virtual_aliases_maps.cf file. I was thinking that maybe the SELECT statement within that file is causing the problem? I do know that I had to insert my own mail_admin password, which has been done.
I am fairly certain that the other components are working. Squirrelmail's "configtest.php" comes back stating that the system is working fine. I can also telnet to amavisd and issue an EHLO command, which returns data, making it seem as though it is working.
One last item - can you give some examples of what data actually goes into the database "mail"? I have added users, a virtual domain and aliases. But some examples would give me a starting point of what the syntax actaully is. Not the INSERT string to add data to the database, but the actaul way the data is setup to be read. For example: if I have a user that has a username of "jdoe1" what would his alias be? And, if the server is currently "server1.mydomain.com" which IS the domain that I am looking to receive mail on, what is the virtual domain?
The ultimate goal of this server is to make it an external smarthost for an internal Microsoft Exchange box. I would appreciate anyone willing to give me some pointers there too once the mail system is actually up and running. I've seen that there are ways to actually pull the AD information using OpenLDAP.
error :(
Submitted by Anonymous visitor (not verified) on Fri, 2007-08-24 07:31.
Vote!Hi.. I have error:
host 127.0.0.1[127.0.0.1] said: 451 4.5.0 Error in processing, id=71084-02, parts_decode_ext FAILED: Unix utility file(1) not available, but is needed at (eval 70) line 113. (in reply to end of DATA command))
Help?