Before configuring the mail server, first understand the basic process and several concepts of Mail sending. MUA: Email User proxy, such as outlook, foxmail on the client, or a webpage such as 163 mailbox. MTA: The mail transmission proxy. After MUA completes the mail and transmits it through MTA, multiple MTA may be used for relay. Here sendmail and postfix are used. MDA: The mail delivery agent. After the MTA finds the target, it sends the email to the specified place and waits for the user to take it away.
The basic process of an email is as follows:
Sender: MUA -- send --> MTA-> several MTA...-> MTA-> MDA <-- receive -- MUA: recipient
The protocols used between MUA and MTA and between MTA are SMTP protocols. When receiving emails, the most common protocols used between MUA and MDA are POP3 or IMAP.
In CentOS, the default MTA (Mail sending proxy) uses sendmail, but this configuration is complicated. Here I choose a more easy-to-use Postfix.
Preparation
1. One U.S. host and CentOS 6
2. One self-owned Domain name
Procedure
1. Modify the hostname
# Hostname mail.sijitao.net
# Vi/etc/sysconfig/network
Modify: HOSTNAME = "mail.sijitao.net"
2. Configure dns
Forward resolution to domain name management, add A record of MX pointing to sijitao.net, mail.sijitao.net respectively to host ip address.
It is resolved to the host provider for modification. Generally, foreign hosts can do this.
Check whether the configuration takes effect. For example:
[Root @ mail ~] # Dig-t mx sijitao.net
; <> DiG 9.8.2rc1-RedHat-9.8.2-0.37.rc1.el6_7.6 <>-t mx sijitao.net
; Global options: + cmd
; Got answer:
;-> HEADER <-opcode: QUERY, status: NOERROR, id: 56108
; Flags: qr rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 0
; Question section:
; Sijitao.net. IN MX
; Answer section:
Sijitao.net. 599 in mx 10 mail.sijitao.net.
; Query time: 303 msec
; SERVER: 8.8.8.8 #53 (8.8.8.8)
; WHEN: Thu Mar 31 10:43:40 2016
; Msg size rcvd: 50
[Root @ mail ~] # Dig-t A mail.sijitao.net
; <> DiG 9.8.2rc1-RedHat-9.8.2-0.37.rc1.el6_7.6 <>-t A mail.sijitao.net
; Global options: + cmd
; Got answer:
;-> HEADER <-opcode: QUERY, status: NOERROR, id: 63586
; Flags: qr rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 0
; Question section:
; Mail.sijitao.net. IN
; Answer section:
Mail.sijitao.net. 599 in a 107.161.16.181
; Query time: 201 msec
; SERVER: 8.8.8.8 #53 (8.8.8.8)
; WHEN: Thu Mar 31 10:43:48 2016
; Msg size rcvd: 50
[Root @ mail ~] # Dig-x 107.161.16.181
; <> DiG 9.8.2rc1-RedHat-9.8.2-0.37.rc1.el6_7.6 <>-x 107.161.16.181
; Global options: + cmd
; Got answer:
;-> HEADER <-opcode: QUERY, status: NOERROR, id: 14444
; Flags: qr rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 0
; Question section:
; 181.16.161.107.in-addr. arpa. IN PTR
; Answer section:
181.16.161.107.in-addr. arpa. 21599 in ptr mail.sijitao.net.
; Query time: 83 msec
; SERVER: 8.8.8.8 #53 (8.8.8.8)
; WHEN: Thu Mar 31 10:43:58 2016
; Msg size rcvd: 75
3. Install postfix
# Yum groupinstall "Development Tools"
# Yum install mysql-server mysql-devel cyrus-sasl-devel cyrus-imapd cyrus-sasl-plain
# Groupadd-g 2525 postfix
# Useradd-g postfix-u 2525-s/sbin/nologin-M postfix
# Groupadd-g 2526 postdrop
# Useradd-g postdrop-u 2526-s/sbin/nologin-M postdrop
# Wget https://archive.mgm51.com/mirrors/postfix-source/official/postfix-2.9.15.tar.gz
# Tar xf postfix-2.9.15.tar.gz
# Cd postfix 2.9.15
# Make makefiles 'ccargs =-DHAS_MYSQL-I/usr/include/mysql-DUSE_SASL_AUTH-DUSE_CYRUS_SASL-I/usr/include/sasl-DUSE_TLS ''' AUXLIBS =-L/usr/lib64 /mysql-lmysqlclient-lz-lm-L/usr/lib64/sasl2-lsasl2-lssl-lcrypto'
# Make
# Make install
# Chmod + x/etc/init. d/postfix
# Chkconfig -- add postfix
# Chkconfig -- list postfix
# Newaliases
Follow the steps above to install the postfix quickly. Here we use our own compilation method, mainly to add mysql and sasl support.
4. Configure postfix
# Cd/etc/postfix
# Vi main. cf
Modify the following configurations as needed.
Myhostname = mail.sijitao.net
Myorigin = sijitao.net
Mydomain = sijitao.net
Mydestination = $ myhostname, localhost. $ mydomain, localhost, $ mydomain
Mynetworks = 127.0.0.0/8, 107.161.16.181/32
Note:
The myorigin parameter is used to specify the sender's domain name, that is, the sender address is disguised;
The mydestination parameter specifies the domain name of the recipient when the postfix receives the Mail, that is, the Mail of the domain name to be received by your postfix system;
The myhostname parameter specifies the host name of the host running the postfix mail system. By default, the value is set to the local machine name;
The mydomain parameter specifies your domain name. By default, postfix deletes the first part of myhostname as the value of mydomain;
The mynetworks parameter specifies the network address of your network. The postfix system determines whether the user is remote or local based on the value. If the user is a local network, the user is allowed to access the network;
The inet_interfaces parameter specifies the network interface that the postfix system listens;
Restart postfix After configuration, and then use telnet to test.
Telnet mail.sijitao.net 25
Helo mail.sijitao.net
Mail from: root@sijitao.net
Rcpt to: abc@sijitao.net
Data
Subject: hello
Hello
.
Quit
If it is normal, an e-mail will be sent to the abc@sijitao.net.
5. Add the sasl authentication module
# Vi/etc/sysconfig/saslauthd
Modify: MECH = shadow
# Vi/etc/sasl2/smtpd. conf
Log_level: 3
Pwcheck_method: saslauthd
Mech_list: PLAIN LOGIN
# Cd/usr/lib64/sasl2/
# Ln-s/etc/sasl2/smtpd. conf smtpd. conf
Test Command: testsaslauthd-u username-p password. If there is no problem with the module, OK is displayed. Here, the user name and password are the account and password of the linux system.
Next, modify the main. cf configuration of postfix again and add the following content:
############################ CYRUS-SASL ########### #################
Broken_sasl_auth_clients = yes
Expiration = permit_mynetworks, permit_sasl_authenticated, reject_invalid_hostname, reject_non_fqdn_hostname, expiration, reject_unauth_pipelining, reject_unauth_destination
Smtpd_sasl_auth_enable = yes
Smtpd_sasl_local_domain = $ myhostname
Smtpd_sasl_security_options = noanonymous
Smtpd_sasl_path = smtpd
Smtpd_banner = Welcome to our $ myhostname ESMTP, Warning: Version not Available!
After modification, restart postfix. After testing again, you can find that authentication is required before sending an email. The user name and password are the user name and password of the linux system.
When using outlook to send a mail, the following error occurs: Helo command rejected: need fully-qualified hostname.
Remove: reject_non_fqdn_hostname
6. mysql authentication
Postfix and mysql authentication are implemented through courier-authlib.
A. Install courier-authlib
Various problems may occur during installation. If the library does not exist, install the library. If you are sure that all of them are in use, try to change the version number.
# Yum install libtool-ltdl-devel
After the dependency is installed, the following are my errors and solutions.
# Yum install libtool-ltdl-devel
# Tar xf courier-authlib-0.66.1.tar.bz2
# Cd courier-authlib-0.66.1
#./Configure \
-- Prefix =/usr/local/courier-authlib \
-- Sysconfdir =/etc \
-- Without-authpam \
-- Without-authshadow \
-- Without-authvchkpw \
-- Without-authpgsql \
-- With-authmysql \
-- With-mysql-libs =/usr/lib64/mysql \
-- With-mysql-nodes des =/usr/include/mysql \
-- With-redhat \
-- With-authmysqlrc =/etc/authmysqlrc \
-- With-authdaemonrc =/etc/authdaemonrc \
-- With-mailuser = postfix \
-- With-mailgroup = postfix \
-- With-ltdl-lib =/usr/lib64 \
-- With-ltdl-include =/usr/include
Error: configure: error: invalid ltdl library directory: '/usr/lib64 /'
# Wget http://ftpmirror.gnu.org/libtool/libtool-2.4.6.tar.gz
# Tar zxvf libtool-2.4.6.tar.gz
#./Configure -- prefix =/usr/local/libtool-2.4.6 -- enable-ltdl-install
# Make
# Make install
Re-compilation and installation are successful.
#./Configure \
-- Prefix =/usr/local/courier-authlib \
-- Sysconfdir =/etc \
-- Without-authpam \
-- Without-authshadow \
-- Without-authvchkpw \
-- Without-authpgsql \
-- With-authmysql \
-- With-mysql-libs =/usr/lib64/mysql \
-- With-mysql-nodes des =/usr/include/mysql \
-- With-redhat \
-- With-authmysqlrc =/etc/authmysqlrc \
-- With-authdaemonrc =/etc/authdaemonrc \
-- With-mailuser = postfix \
-- With-mailgroup = postfix \
-- With-ltdl-lib =/usr/local/libtool-2.4.6/lib \
-- With-ltdl-include =/usr/local/libtool-2.4.6/include
Install
# Make
# Make install
# Chmod 755/usr/local/courier-authlib/var/spool/authdaemon
# Cp/etc/authdaemonrc. dist/etc/authdaemonrc
# Cp/etc/authmysqlrc. dist/etc/authmysqlrc
Modify the configurations of courier-authlib as follows:
# Vi/etc/authdaemonrc
Authmodulelist = "authmysql"
Authmodulelistorig = "authmysql"
Daemons = 10
# Vi/etc/authmysqlrc
MYSQL_SERVER xxx
MYSQL_USERNAME xxx
MYSQL_PASSWORD xxx
MYSQL_PORT xxx
MYSQL_DATABASE xxx
MYSQL_USER_TABLE mailbox
MYSQL_CRYPT_PWFIELD password
MYSQL_UID_FIELD 2525
MYSQL_GID_FIELD 2525
MYSQL_LOGIN_FIELD username
MYSQL_HOME_FIELD concat ('/var/mailbox/', homedir)
MYSQL_MAILDIR_FIELD concat ('/var/mailbox/', maildir)
After the configuration is modified, enable the courier-authlib service.
# Cp courier-authlib.sysvinit/etc/rc. d/init. d/courier-authlib
# Chmod 755/etc/init. d/courier-authlib
# Chkconfig -- level 2345 courier-authlib on
# Service courier-authlib start
B. Modify smtp authentication configuration
We used shadow for smtp authentication, that is, the user name and password of the linux system. Now you need to change it to courier-authlib.
# Mkdir-pv/var/mailbox
# Chown-R postfix/var/mailbox/
Reconfigure SMTP Authentication, edit/etc/sasl2/smtpd. conf, and make sure it is the following content:
Pwcheck_method: authdaemond
Log_level: 3
Mech_list: PLAIN LOGIN
Authdaemond_path:/usr/local/courier-authlib/var/spool/authdaemon/socket
C. Add postfix configuration
######################## Virtual Mailbox Settings ############# ###########
Virtual_mailbox_base =/var/mailbox
Virtual_mailbox_maps = mysql:/etc/postfix/mysql_virtual_mailbox_maps.cf
Virtual_mailbox_domains = mysql:/etc/postfix/mysql_virtual_domains_maps.cf
Virtual_alias_domains =
Virtual_alias_maps = mysql:/etc/postfix/mysql_virtual_alias_maps.cf
Virtual_uid_maps = static: 2525
Virtual_gid_maps = static: 2525
Virtual_transport = virtual
########################## QUOTA Settings ############ ############
Message _ size_limit = 14336000
Virtual_mailbox_limit = 20971520
D. Import mysql
For mysql authentication management, extman is used to download extman from the Internet. After adding a proper database name, import the docs/extmail. SQL and docs/init. SQL statements in extman and create the mysql User name and password.
Copy objects, mysql_virtual_domains_maps.cf, mysql_virtual_limit_maps.cf, mysql_virtual_mailbox_maps.cf, and mysql_virtual_sender_maps.cf to the/etc/postfix directory, and modify database connection information based on actual conditions.
E. Modify the postfix and remove the center domain.
Log out of myhostname, mydomain, myorigin, and mydestination, and restart postfix.
7. Install nginx extman
At this point, postfix and mysql authentication has been configured, but for ease of management, we recommend that you install the extman web interface.
# Yum install spawn-fcgi-devel fcgi
Install fcgiwrap at http://github.com/gnosek/fcgiwrap/tarball/master. The version uses a fcgiwrap-1.0.1, and everything else is wrong.
# Tar zxvf your downloaded example .tar.gz
# Cd gnosek-fcgiwrap-1328862/
# Autoreconf-I
#./Configure
# Make
# Cp fcgiwrap/usr/local/bin/
Start fcgiwrap
Spawn-fcgi-f/usr/local/bin/fcgiwrap-a 127.0.0.1-p 9001-F 3-P/var/run/fastcgi-c.pid
Nginx configuration
Log_format extmanlog '$ remote_addr-$ remote_user [$ time_local] "$ request "'
'$ Status $ body_bytes_sent "$ http_referer "'
'"$ Http_user_agent" $ http_x_forwarded_for ';
Server
{
Listen 80;
Server_name extman.sijitao.net;
Index index.html index.htm index. php index. cgi;
Root/home/wwwroot/extsuite/extman/html /;
Location ~ . * \. (Gif | jpg | jpeg | png | bmp | swf) $
{
Rewrite ^/extman/default/images/(. *)/default/images/$1 break;
Expires 30d;
}
Location ~ . * \. (Js | css )? $
{
Rewrite ^/extman/default/(. *)/default/$1 break;
Expires 1 h;
}
Location/extman/cgi /{
Root/home/wwwroot/extsuite/extman/cgi;
Fastcgi_pass 127.0.0.1: 9001;
Fastcgi_index index. cgi;
Rewrite ^/extman/cgi/(. *) \. cgi/$ 1.cgi break;
Include fastcgi. conf;
}
Access_log/home/wwwlogs/extmanlog. log extmanlog;
}
Nginx installation is complete. Several problems are encountered when the page is opened.
A. Error: Can't locate FCGI. pm in
Yum install fcgi-perl
B. Error: Can't locate DBD/mysql. pm
Yum install perl-DBD-MySQL
C. Error: Can't open/tmp/extman // sid_68bed5adf6321a50972fecd642e94805, No such file or directory
Mkdir-pv/tmp/extman
Chown www: www/tmp/extman/
Finally, log on to extman, add domain names and users, and send an email to test. If you want to accept the email, you can configure another dovecot.