Building a FreeBSD messaging system using Postfix (Simplified edition)

Source: Internet
Author: User
Tags chmod install php imap mx record squirrelmail
As a result of the writing of an article also just contact Postfix, the e-mail system is also very superficial understanding, although barely built to run the mail system, but also exposed a lot of problems. At the same time blind pursuit of function, make the whole installation process is long, for want to get started friend is more difficult. This time I will revise the previous article, and remove the search and anti-spam functions, complete the installation, to establish a full e-mail function, but less secure mail system, for beginners to learn from friends.
Postfix based messaging systems can be divided into 3 parts, including SMTP, IMAP/POP3, and authentication, which are implemented by Postfix/courier-imap and Courier-authdaemond respectively, In which Courier-authdaemond also call CYRUS-SASL2 for verification. All the data of the mail system can be saved in Ldap/pgsql or MySQL. To make the installation process easy to understand, this article will use MySQL.

0. Update ports
Pkg_add-r CVSup
1. Installation SASL2
SASL2 is a package that is required for SMTP authentication, and because Postfix is installed with the default configuration, SASL does not support Courier-authdaemond, so you need to first install with the options you specify.
Make With_authdaemon=yes Install clean
2. Installation Postfix
Make Config
Select [PCRE], [SASL2], [MySQL], [VDA],SASL2 for SMTP authentication, MySQL for data tables, the VDA is used to support virtual postings.
Make with_mysql_ver=51 Install clean
Specifies that the 5.1 version of MySQL is installed, note that the mysql-client is installed here, and you will need to install mysql-server later. Y is selected two times during installation to activate Postfix
3. Installation Courier-imap
Make Config
SELECT [Auth_mysql]
Make install clean
4. Installation Mysql-server
Make with_charset=gb2312 Install clean
5, install Apache. Edit httpd.conf to set the home directory to/usr/local/www after Setup completes
Make install clean

6, install PHP. Update ports after the installation of PHP changes, first in make config need to select [Apache] to compile the Apache module, after the installation in Httpd.conf modified 2 configuration:
A, add index.php in the DirectoryIndex
B, join AddType application/x-httpd-php. php
Make Config
Make install clean
7, install Php5-extensions. Select modules as needed to ensure that [MYSQL], [PCRE], [session] is selected.
Make Config
Make install clean

8, install Postfixadmin. Move the Web page to/usr/www/data/after Setup completes
Make install clean
9. Installation SquirrelMail
Make install clean
At this point, the required software is all installed, and the following will be configured in turn.
Note: The following configuration file must have no spaces at the end of each line.

1. Configure SASL2
Mech_list:plain LOGIN
2. Configure MySQL Database
Chown-r Mysql:mysql/var/db/mysql
Mysql-uroot-p < Database_mysql. Txt
3. Configure Postfix
Use the same user as Apache to read the Mail directory because the Apache user is www,id:80, so be aware of the user ID in/USR/LOCAL/ETC/POSTFIX/MAIN.CF.
Chown-r www:www/usr/local/virtual
Chmod-r 775/usr/local/virtual
At the end add:
#======= BASE ==============
#myhostname =
#mydomain =
Home_mailbox = maildir/
#mydestination = $myhostname
#local_recipient_maps =
#======= MYSQL =============
Virtual_gid_maps = static:80
Virtual_mailbox_base =/usr/local/virtual
Virtual_uid_maps = static:80
Virtual_minimum_uid = 80
Virtual_alias_maps = mysql:/usr/local/etc/postfix/mysql/
Virtual_mailbox_domains = mysql:/usr/local/etc/postfix/mysql/
Virtual_mailbox_maps = mysql:/usr/local/etc/postfix/mysql/
#======= Quota ============
Message_size_limit = 5242880
Virtual_mailbox_limit_inbox = No
Virtual_mailbox_limit_override = yes
virtual_maildir_extended = yes
Virtual_create_maildirsize = yes
Virtual_mailbox_limit_maps = mysql:/usr/local/etc/postfix/mysql/
Virtual_mailbox_limit = 52428800
#======== SASL ================
Smtpd_sasl_auth_enable = yes
Smtpd_sasl_security_options = noanonymous
Broken_sasl_auth_clients = yes
Smtpd_recipient_restrictions = permit_sasl_authenticated Permit_auth_destination Reject
#smtpd_sasl_local_domain = $mydomain
Smtpd_client_restrictions = permit_sasl_authenticated

As you can see from the configuration above, there are 4 tables stored in the MySQL database, Virtual_alias (virtual alias), Virtual_domains (virtual domain), virtual_mailbox_maps (virtual mailbox map), and Virtual_ Mailbox_limit (Virtual mailbox limit). The specific tables and fields that postfix access to MySQL are set by 4 corresponding configuration files.
mkdir MySQL

1. EE
user = Postfix
Password = postfix
hosts = localhost
dbname = Postfix
Table = Alias
Select_field = Goto
Where_field = Address

2. EE
user = Postfix
Password = postfix
hosts = localhost
dbname = Postfix
Table = Domain
Select_field = description
Where_field = Domain

3. EE
user = Postfix
Password = postfix
hosts = localhost
dbname = Postfix
Table = Mailbox
Select_field = Maildir
Where_field = Username

4. EE
user = Postfix
Password = postfix
hosts = localhost
dbname = Postfix
Table = Mailbox
Select_field = Quota
Where_field = Username

4. Configure Courier-authdaemond
./courier-authdaemond Start #脚本文件名可能是
chmod O+x/var/run/authdaemond
Modify Authmodulelist and Authmodulelistorig to specify that only MySQL is used for authentication
Authmodulelist= "Authmysql"
Authmodulelistorig= "Authmysql"
Set the AUTHMYSQLRC so that Authdaemond can query MySQL, and note that the spaces at the end of each line are deleted.
Mysql_crypt_pwfield Password
mysql_database postfix
Mysql_gid_field ' 80 '
Mysql_home_field '/usr/local/virtual '
Mysql_login_field username
Mysql_maildir_field MAILDIR
Mysql_name_field NAME
Mysql_opt 0
Mysql_password postfix
Mysql_server localhost
Mysql_uid_field ' 80 '
Mysql_username postfix
Mysql_user_table Mailbox
5. Configure Startup Items
Add the following entries:
Sendmail_enable= "NONE"
Postfix_enable= "YES"
Apache22_enable= "YES"
Mysql_enable= "YES"
Courier_authdaemond_enable= "YES"
Courier_imap_imapd_enable= "YES"
Courier_imap_pop3d_enable= "YES"
6, restart the computer
7. Configure Postfixadmin
$CONF [' default_language '] = ' cn ';
$CONF [' admin_email '] = ' ';
$CONF [' domain_path '] = ' YES ';
$CONF [' domain_in_mailbox '] = ' NO ';
$CONF [' quota '] = ' YES ';

Check to see if the installation was successful through http://localhost/postfixadmin/setup.php.
Enter the http://localhot/postfixadmin/admin into the admin page and set up the virtual domain and user.
Observe whether the corresponding domain name directory and user directory appear under/usr/local/virtual.
Note: If you create a new virtual domain with the same local domain name in postfixadmin, you may not be able to create the appropriate domain name and user's folder. This situation should be resolved through MX records. If the mail server is on, you should specify the domain name of the postfix as, and then add an MX record to point to, so you can establish a virtual domain.
8. Configure SquirrelMail
Option 10. Languages
The settings are as follows:
2. Default charset:gb2312
Save exit
Enter the http://localhost/squirrelmail/test mailbox.

Note: In addition to the Default_domain specified in AUTHMYSQLRC, the full e-mail address needs to be entered for other domain users to log in.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.