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
CVSUP-GL 2-h Cvsup.freebsdchina.org/usr/share/examples/cvsup/ports-supfile
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.
Cd/usr/ports/security/cyrus-sasl2
Make With_authdaemon=yes Install clean
2. Installation Postfix
Cd/usr/ports/mail/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
Cd/usr/ports/mail/courier-imap
Make Config
SELECT [Auth_mysql]
Make install clean
4. Installation Mysql-server
Cd/usr/ports/databases/mysql51-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
Cd/usr/ports/www/apache22
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
Cd/usr/ports/lang/php5
Make Config
Make install clean
7, install Php5-extensions. Select modules as needed to ensure that [MYSQL], [PCRE], [session] is selected.
Cd/usr/ports/lang/php5-extensions
Make Config
Make install clean

8, install Postfixadmin. Move the Web page to/usr/www/data/after Setup completes
Cd/usr/ports/mail/postfixadmin
Make install clean
mv/usr/local/www/postfixadmin/usr/local/www/data/
9. Installation SquirrelMail
Cd/usr/ports/mail/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
Ee/usr/local/lib/sasl2/smtpd.conf
Pwcheck_method:authdaemond
Log_level:3
Mech_list:plain LOGIN
Authdaemond_path:/var/run/authdaemond/socket
2. Configure MySQL Database
Chown-r Mysql:mysql/var/db/mysql
cd/usr/local/bin/
./mysql_install_db
Cd/usr/local/libexec
./mysqld--user=mysql&
Cd/usr/local/www/postfixadmin
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.
Newaliases
Mkdir-p/usr/local/virtual
Chown-r www:www/usr/local/virtual
Chmod-r 775/usr/local/virtual
Ee/usr/local/etc/postfix/main.cf
At the end add:
#======= BASE ==============
#myhostname =
#mydomain = example.com
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_alias_maps.cf
Virtual_mailbox_domains = mysql:/usr/local/etc/postfix/mysql/virtual_domains_maps.cf
Virtual_mailbox_maps = mysql:/usr/local/etc/postfix/mysql/virtual_mailbox_maps.cf
#======= 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_maps.cf
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.
cd/usr/local/etc/postfix/
mkdir MySQL
CD MySQL

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

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

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

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

4. Configure Courier-authdaemond
Cd/usr/local/etc/rc.d
./courier-authdaemond Start #脚本文件名可能是courier-authdaemond.sh
chmod O+x/var/run/authdaemond
Cd/usr/local/etc/authlib
EE AUTHDAEMONRC
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.
EE AUTHMYSQLRC
Default_domain example.com
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_PORT 0
#MYSQL_QUOTA_FIELD QUOTA
Mysql_server localhost
Mysql_uid_field ' 80 '
Mysql_username postfix
Mysql_user_table Mailbox
5. Configure Startup Items
Ee/etc/rc.conf
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
Reboot
7. Configure Postfixadmin
Cd/usr/local/www/data/postfixadmin
EE config.inc.php
$CONF [' default_language '] = ' cn ';
$CONF [' admin_email '] = ' postmaster@example.com ';
$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 example.com, you should specify the domain name of the postfix as mail.example.com, and then add an MX record to point to mail.example.com, so you can establish a example.com virtual domain.
8. Configure SquirrelMail
Cd/usr/local/www/data/squirrelmail
./configure
Option 10. Languages
The settings are as follows:
1. Default LANGUAGE:ZH_CN
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: info-contact@alibabacloud.com 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.