Linux build postfix mail server

Source: Internet
Author: User
Tags auth bz2 chmod syslog dovecot iptables

-------Start command

Systemctl Start Dovecot

Service Courier-authlib Restart

Systemctl Status Courier-authlib

Systemctl Enable Courier-authlib

Systemctl Start SASLAUTHD

Systemctl Enable SASLAUTHD


-------postfix-------Configuration


First, equipment work

Setenforce 0

Systemctl Stop Firewalld

Iptables-p INPUT ACCEPT

Iptables-f

Iptables-x

Iptables-l


Second, install mysql5.7 Epel source

Yum install-y wget

wget http://dev.mysql.com/get/mysql-community-release-el7-5.noarch.rpm

RPM-IVH mysql-community-release-el7-5.noarch.rpm

wget http://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm

RPM-IVH epel-release-latest-7.noarch.rpm


Third, installation Postfix

1, uninstall the system comes with Postfix, delete postfix user, reassign uid, GID create new user Postfix,postdrop

Yum Remove postfix-y

Userdel postfix

Groupdel Postdrop

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


2, download the source package and unzip the compilation

wget http://mirrors.go-parts.com/postfix/source/official/postfix-3.0.1.tar.gz

Tar XF postfix-3.0.1.tar.gz

CD postfix-3.0.1

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-lrt-lm-l/usr/lib64/sasl2-lsasl2-lssl-lcrypto '

Make && make install


3, change the directory belongs to the main genus Group

Chown-r Postfix:postdrop/var/spool/postfix

Chown-r postfix:postdrop/var/lib/postfix/

Chown Root/var/spool/postfix

Chown-r Root/var/spool/postfix/pid


4, modify the Postfix configuration file

[Email protected] ~]# VIM/ETC/POSTFIX/MAIN.CF

Myhostname = mail.everyoo.com//Set host name

MyDomain = everyoo.com//Specify Domain name

Myorigin = $mydomain//Indicates the domain name where the sender is located

Inet_interfaces =//all Specifies the network interface that the Postfix system listens on

mydestination = $myhostname, localhost. $mydomain, localhost, $mydomain//Specify postfix the recipient's domain name when receiving the message [Disable using the virtual domain]

Mynetworks_style = host//Specify trust segment type

Mynetworks = 192.168.1.0/24, 127.0.0.0/8//Specify Trusted Clients

Relay_domains = $mydestination//Specify the domain name that allows brokered mail

Alias_maps = hash:/etc/aliases//set alias for mail


Iv. installation of Dovecot

Yum install-y dovecot Dovecot-mysql

cd/etc/dovecot/

Vim dovecot.conf

protocols = IMAP POP3

!include conf.d/*.conf

Listen = *

Base_dir =/var/run/dovecot/

CD conf.d/

Vim 10-auth.conf

Disable_plaintext_auth = No

Vim 10-mail.conf

Mail_location = Maildir:~/maildir

Mail_location = Maildir:/var/mailbox/%d/%n/maildir

Mail_privileged_group = Mail

Vim 10-ssl.conf

SSL = No

Vim 10-logging.conf Og_path =/var/log/dovecot.log

Info_log_path =/var/log/dovecot.info

Log_timestamp = "%y-%m-%d%h:%m:%s"

CP Auth-sql.conf.ext auth-sql.conf

Vim auth-sql.conf

PASSDB {driver = sql args =/etc/dovecot/dovecot-sql.conf.ext}# Path for SQL configuration file, see Example-config/dov Ecot-sql.conf.ext

USERDB {driver = sql args =/etc/dovecot/dovecot-sql.conf.ext}


V. Installation of Courier-authlib

wget https://sourceforge.net/projects/courier/files/courier-unicode/1.2/courier-unicode-1.2.tar.bz2

Tar XF courier-unicode-1.2.tar.bz2

CD courier-unicode-1.2

./configure

Make && make install


wget https://sourceforge.net/projects/courier/files/authlib/0.66.2/courier-authlib-0.66.2.tar.bz2

Tar XF courier-authlib-0.66.2.tar.bz2

CD courier-authlib-0.66.2

./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-includes=/usr/include/mysql \

--with-redhat \

--WITH-AUTHMYSQLRC=/ETC/AUTHMYSQLRC \

--WITH-AUTHDAEMONRC=/ETC/AUTHDAEMONRC \

--with-mailuser=postfix

Make && make install


2, Configuration Courier-authlib

chmod 755/usr/local/courier-authlib/var/spool/authdaemon

Cp/etc/authdaemonrc.dist/etc/authdaemonrc

Cp/etc/authmysqlrc.dist/etc/authmysqlrc

Vim/etc/authdaemonrc

Authmodulelist= "Authmysql"

Authmodulelistorig= "Authmysql"

Vim/etc/authmysqlrc

Mysql_server localhost

Mysql_username Extmail

Mysql_password Extmail

Mysql_socket/var/lib/mysql/mysql.sock

Mysql_port 3306

Mysql_database Extmail

Mysql_user_table Mailbox

Mysql_crypt_pwfield Password

Default_domain test.com

Mysql_uid_field ' 2525 '

Mysql_gid_field ' 2525 '

Mysql_login_field username

Mysql_home_field concat ('/var/mailbox/', homedir)

Mysql_name_field NAME

Mysql_maildir_field concat ('/var/mailbox/', MAILDIR)

3, Courier-authlib Add service startup script and other

CP Courier-authlib.sysvinit/etc/init.d/courier-authlib

chmod +x/etc/init.d/courier-authlib

Chkconfig--add Courier-authlib

Chkconfig Courier-authlib on

echo "/usr/local/courier-authlib/lib/courier-authlib" >>/etc/ld.so.conf.d/courier-authlib.conf

Ldconfig

Service Courier-authlib Start


4. SMTP and virtual user-related settings

vim/usr/lib64/sasl2/smtpd.conf//file does not exist, create it yourself

Pwcheck_method:authdaemond

Log_level:3

Mech_list:plain LOGIN

Authdaemond_path:/usr/local/courier-authlib/var/spool/authdaemon/socket

Vim/etc/postfix/main.cf

# #postfix支持SMTP # #

Smtpd_sasl_auth_enable = yes

Smtpd_sasl_local_domain = ' '

Smtpd_recipient_restrictions = Permit_mynetworks,permit_sasl_authenticated,reject_unauth_destination

Broken_sasl_auth_clients=yes

Smtpd_client_restrictions = permit_sasl_authenticated

Smtpd_sasl_security_options = noanonymous

# #postfix支持虚拟用户 # #

Virtual_mailbox_base =/var/mailbox

Virtual_mailbox_maps = MYSQL:/ETC/POSTFIX/MYSQL_VIRTUAL_MAILBOX_MAPS.CF//The configuration file here needs to be in the back Extman

Copy it over there.

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


Vi. installation of Extmail

Extmail and Extman can be downloaded through these two links

Http://7xivyw.com1.z0.glb.clouddn.com/extmail-1.2.tar.gz

Http://7xivyw.com1.z0.glb.clouddn.com/extman-1.1.tar.gz


Mkdir-p/var/www/extsuite

Tar XF extmail-1.2.tar.gz-c/var/www/extsuite/

MV/VAR/WWW/EXTSUITE/EXTMAIL-1.2//var/www/extsuite/extmail


2. Change the Extmail configuration file

Cd/var/www/extsuite/extmail

CP Webmail.cf.default WEBMAIL.CF

Vim WEBMAIL.CF

Sys_sess_dir =/tmp/extmail

Sys_upload_tmpdir =/tmp/extmail/upload

Sys_user_lang = ZH_CN

Sys_min_pass_len = 8

Sys_maildir_base =/var/mailbox

Sys_mysql_user = Extmail

Sys_mysql_pass = Extmail

sys_mysql_db = Extmail

Sys_mysql_host = localhost

Sys_mysql_socket =/var/lib/mysql/mysql.sock

sys_mysql_table = Mailbox

Sys_mysql_attr_username = USERNAME

Sys_mysql_attr_domain = DOMAIN

SYS_MYSQL_ATTR_PASSWD = password

Sys_authlib_socket =/usr/local/courier-authlib/var/spool/authdaemon/socket


3. Set up temporary files directory and Session Directory

Mkdir-p/tmp/extmail/upload

Chown-r postfix.postfix/tmp/extmail/


Vii. installation of Extman

Tar XF extman-1.1.tar.gz-c/var/www/extsuite/

cd/var/www/extsuite/

MV Extman-1.1/extman


2. Change the Extman configuration file

CD extman/

CP Webman.cf.default WEBMAN.CF


3. Change the CGI directory belongs to the main genus Group

Chown-r postfix.postfix/var/www/extsuite/extman/cgi/

Chown-r postfix.postfix/var/www/extsuite/extmail/cgi/


4. Import the database

Vim Docs/extmail.sql

:% s/type/engine/g

Vim/etc/my.cnf

# Recommended in standard MySQL setup

#sql_mode =no_engine_substitution,strict_trans_tables//Take this line and restart MySQL, it is important to note that after the database import is successful, this is not to be removed from the comment, Otherwise, MySQL will not start up.

Mysql-uroot < Docs/extmail.sql

Mysql-uroot < Docs/init.sql


5. Create database user Extmail and grant permissions

GRANT all on extmail.* to [email protected] '% ' identified by ' extmail ';

FLUSH privileges;


6. Copy the configuration file mentioned in four-4

cd/var/www/extsuite/extman/docs/

CP mysql_virtual_*/etc/postfix/


Mkdir/tmp/extman

Chown-r postfix.postfix/tmp/extman/


7, start Postfix, Dovecot, SASLAUTHD

Ss-tnluo | Grep:25

PS aux | grep dovecot

PS aux | grep SASLAUTHD


Eight, testing

/USR/LOCAL/COURIER-AUTHLIB/SBIN/AUTHTEST-S login [email protected] Extmail

Mkdir/var/mailbox

Chown-r postfix.postfix/var/mailbox/


Vim/etc/nginx/fcgi.conf

Fastcgi_param Gateway_interface cgi/1.1;

Fastcgi_param Server_software Nginx;

Fastcgi_param query_string $query _string;

Fastcgi_param Request_method $request _method;

Fastcgi_param Content_Type $content _type;

Fastcgi_param content_length $content _length;

Fastcgi_param script_name $fastcgi _script_name;

Fastcgi_param Request_uri $request _uri;

Fastcgi_param document_root $document _root;

Fastcgi_param server_protocol $server _protocol;

Fastcgi_param remote_addr $remote _addr;

Fastcgi_param Remote_port $remote _port;

Fastcgi_param server_addr $server _addr;

Fastcgi_param server_port $server _port;

Fastcgi_param server_name $server _name;


wget http://www.cpan.org/authors/id/M/MH/MHARNISCH/Unix-Syslog-1.1.tar.gz

Tar XF unix-syslog-1.1.tar.gz

CD unix-syslog-1.1

Perl makefile.pl

Make && make install


Install the certificate to postfix and configure the Postfix

Vi/etc/postfix/main.cf

Smtpd_use_tls = yes

Smtpd_tls_key_file =/etc/postfix/mailkey.pem

Smtpd_tls_cert_file =/etc/postfix/mail_signed_cert.pem

Smtpd_tls_cafile =/etc/postfix/cacert.pem


Smtp_use_tls = yes

Smtp_tls_note_starttls_offer = yes

Smtp_tls_key_file =/etc/postfix/mailkey.pem

Smtp_tls_cert_file =/etc/postfix/mail_signed_cert.pem

Smtp_tls_cafile =/etc/postfix/cacert.pem


Service Postfix Restart


Open the 465 (SMTPS) port, you need to do the following

Modify the/etc/postfix/master.cf file

Under SMTP inet n-n--smtpd line, add the following line:

Smtps inet n-n--Smtpd-o Smtpd_tls_wrappermode=yes


Vi/etc/dovecot/conf.d/10-ssl.conf

SSL = yes

Ssl_cert = </etc/pki/tls/certs/server.crt

Ssl_key = </etc/pki/tls/certs/server.key


Linux build postfix mail server

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.