当前位置: 代码迷 >> 综合 >> Postfix+Saslauthd+Dovecot+Postfixadmin+RoundCube部署邮件服务器
  详细解决方案

Postfix+Saslauthd+Dovecot+Postfixadmin+RoundCube部署邮件服务器

热度:35   发布时间:2024-02-08 22:50:20.0

一、安装部署Postfix

1.Postfix简介

Postfix是Wietse Venema在IBM的GPL协议之下开发的MTA(邮件传输代理)软件
Postfix是Wietse Venema想要为使用最广泛的sendmail提供替代品的一个尝试
Postfix试图更快、更容易管理、更安全,同时还与sendmail保持足够的兼容性

2.设置计算机名称、关闭防火墙、关闭selinux、语言设置为中文、卸载系统sendmail、添加hosts域名映射

hostnamectl set-hostname localhost.localdomainvi /etc/selinux/config
SELINUX=disabledlocalectl set-locale LANG='zh_CN.UTF-8'systemctl disable firewalldyum remove -y sendmail*vim /etc/hosts
127.0.0.1   mail.swireb.cn swireb.cn

3.安装Postfix

yum install -y postfix*

4.Postfix默认安装路径

rpm -ql postfix|more 
/etc/pam.d/smtp
/etc/pam.d/smtp.postfix
/etc/postfix
/etc/postfix/access
/etc/postfix/canonical
/etc/postfix/generic
/etc/postfix/header_checks
/etc/postfix/main.cf
/etc/postfix/master.cf

5.Postfix服务配置

#备份文件
cp /etc/postfix/main.cf /etc/postfix/main.cf.back#修改配置文件
vim /etc/postfix/main.cf#myhostname参数设置主机名称
# The myhostname parameter specifies the internet hostname of this
# mail system. The default is to use the fully-qualified domain name
# from gethostname(). $myhostname is used as a default value for many
# other configuration parameters.
#
#myhostname = host.domain.tld
myhostname = mail.swireb.cn #mydomain参数设置域名
# The mydomain parameter specifies the local internet domain name.
# The default is to use $myhostname minus the first component.
# $mydomain is used as a default value for many other configuration
# parameters.
#
mydomain = swireb.cn  #myorigin参数设置邮箱后缀
# The myorigin parameter specifies the domain that locally-posted
# mail appears to come from. The default is to append $myhostname,
# which is fine for small sites. If you run a domain with multiple
# machines, you should (1) change this to $mydomain and (2) set up
# a domain-wide alias database that aliases each user to
# user@that.users.mailhost.
#
# For the sake of consistency between sender and recipient addresses,
# myorigin also specifies the default domain name that is appended
# to recipient addresses that have no @domain part.
#
#myorigin = $myhostname
myorigin = $mydomain#inet_interfaces参数设置监听地址
# The inet_interfaces parameter specifies the network interface
# addresses that this mail system receives mail on. By default,
# the software claims all active interfaces on the machine. The
# parameter also controls delivery of mail to user@[ip.address].
#
# See also the proxy_interfaces parameter, for network addresses that
# are forwarded to us via a proxy or network address translator.
#
# Note: you need to stop/start Postfix when this parameter changes.
#
inet_interfaces = all  #监听所有网卡
#inet_interfaces = $myhostname
#inet_interfaces = $myhostname, localhost
#inet_interfaces = localhost#inet_protocols参数设置打开IPV4或者IPV6
# Enable IPv4, and IPv6 if supported
inet_protocols = ipv4#mydestination参数设置能够接收信件的主机名称
# The mydestination parameter specifies the list of domains that this
# machine considers itself the final destination for.
#
# These domains are routed to the delivery agent specified with the
# local_transport parameter setting. By default, that is the UNIX
# compatible delivery agent that lookups all recipients in /etc/passwd
# and /etc/aliases or their equivalent.
#
# The default is $myhostname + localhost.$mydomain. On a mail domain
# gateway, you should also include $mydomain.
#
# Do not specify the names of virtual domains - those domains are
# specified elsewhere (see VIRTUAL_README).
#
# Do not specify the names of domains that this machine is backup MX
# host for. Specify those names via the relay_domains settings for
# the SMTP server, or use permit_mx_backup if you are lazy (see
# STANDARD_CONFIGURATION_README).
#
# The local machine is always the final destination for mail addressed
# to user@[the.net.work.address] of an interface that the mail system
# receives mail on (see the inet_interfaces parameter).
#
# Specify a list of host or domain names, /file/name or type:table
# patterns, separated by commas and/or whitespace. A /file/name
# pattern is replaced by its contents; a type:table is matched when
# a name matches a lookup key (the right-hand side is ignored).
# Continue long lines by starting the next line with whitespace.
#
# See also below, section "REJECTING MAIL FOR UNKNOWN LOCAL USERS".
#
#mydestination = $myhostname, localhost.$mydomain, localhost 
mydestination = $myhostname, localhost.$mydomain, localhost, $mydomain
#mydestination = $myhostname, localhost.$mydomain, localhost, $mydomain,
# mail.$mydomain, www.$mydomain, ftp.$mydomain#mynetworks参数设置指定受信任SMTP的列表(受信任的SMTP客户端允许通过Postfix传递邮件)
# Alternatively, you can specify the mynetworks list by hand, in
# which case Postfix ignores the mynetworks_style setting.
#
# Specify an explicit list of network/netmask patterns, where the
# mask specifies the number of bits in the network part of a host
# address.
#
# You can also specify the absolute pathname of a pattern file instead
# of listing the patterns here. Specify type:table for table-based lookups
# (the value on the table right-hand side is not used).
#
mynetworks = 0.0.0.0/0
#mynetworks = $config_directory/mynetworks
#mynetworks = hash:/etc/postfix/network_table#relay_domains参数设置转发邮件域名
# The relay_domains parameter restricts what destinations this system will
# relay mail to. See the smtpd_recipient_restrictions description in
# postconf(5) for detailed information.
#
# By default, Postfix relays mail
# - from "trusted" clients (IP address matches $mynetworks) to any destination,
# - from "untrusted" clients to destinations that match $relay_domains or
# subdomains thereof, except addresses with sender-specified routing.
# The default relay_domains value is $mydestination.
# 
# In addition to the above, the Postfix SMTP server by default accepts mail
# that Postfix is final destination for:
# - destinations that match $inet_interfaces or $proxy_interfaces,
# - destinations that match $mydestination
# - destinations that match $virtual_alias_domains,
# - destinations that match $virtual_mailbox_domains.
# These destinations do not need to be listed in $relay_domains.
# 
# Specify a list of hosts or domains, /file/name patterns or type:name
# lookup tables, separated by commas and/or whitespace. Continue
# long lines by starting the next line with whitespace. A file name
# is replaced by its contents; a type:name table is matched when a
# (parent) domain appears as lookup key.
#
# NOTE: Postfix will not automatically forward mail for domains that
# list this system as their primary or backup MX host. See the
# permit_mx_backup restriction description in postconf(5).
#
relay_domains = $mydestination#alias_maps参数设置邮件别名路径
# The alias_maps parameter specifies the list of alias databases used
# by the local delivery agent. The default list is system dependent.
#
# On systems with NIS, the default is to search the local alias
# database, then the NIS alias database. See aliases(5) for syntax
# details.
# 
# If you change the alias database, run "postalias /etc/aliases" (or
# wherever your system stores the mail alias file), or simply run
# "newaliases" to build the necessary DBM or DB file.
#
# It will take a minute or so before changes become visible. Use
# "postfix reload" to eliminate the delay.
#
#alias_maps = dbm:/etc/aliases
alias_maps = hash:/etc/aliases
#alias_maps = hash:/etc/aliases, nis:mail.aliases
#alias_maps = netinfo:/aliases#alias_database参数设置邮件别名数据库路径
# The alias_database parameter specifies the alias database(s) that
# are built with "newaliases" or "sendmail -bi". This is a separate
# configuration parameter, because alias_maps (see above) may specify
# tables that are not necessarily all under control by Postfix.
#
#alias_database = dbm:/etc/aliases
#alias_database = dbm:/etc/mail/aliases
alias_database = hash:/etc/aliases
#alias_database = hash:/etc/aliases, hash:/opt/majordomo/aliases

6.开启Postfix服务(服务统一在后面开启)

二、安装部署cyrus-sasl

1.cyrus-sasl简介

#Saslauthd服务作用:提供SMTP用户验证,检查用户名和密码是否正确,基于系统shadow文件实现验证配置

2.安装cyrus-sasl

#默认安装的有这个认证软件cyrus-sasl
rpm -qa|grep cyrus
cyrus-sasl-lib-2.1.26-23.el7.x86_64
cyrus-sasl-2.1.26-23.el7.x86_64#没有软件的话yum安装一下
yum install -y cyrus-sasl*

3.开启Saslauthd服务,提供SMTP用户验证(服务统一在后面开启)

三、安装部署Dovecot

1.Dovecot简介

#Dovecot是一个开源的IMAP和POP3邮件服务器,支持Linux/Unix系统,作为IMAP/POP3服务器,Dovecot为邮件用户代理(MUA)提供了一种访问服务器上存储的邮件方法#PS:Dovecot并不负责从其他邮件服务器接受邮件,Dovecot只是将已存储在邮件服务器上的邮件通过MUA显示出来

2.安装Dovecot

yum install -y dovecot* 

3.Dovecot服务配置

#开启POP3协议,默认只开启了IMAP的认证
vim /etc/dovecot/dovecot.conf
# Protocols we want to be serving.
protocols = imap pop3 lmtp   #开启POP3# A comma separated list of IPs or hosts where to listen in for connections. 
# "*" listens in all IPv4 interfaces, "::" listens in all IPv6 interfaces.
# If you want to specify non-default ports or anything more complex,
# edit conf.d/master.conf.
listen = *   #监听全部

4.Dovecot服务配置禁止SSL登录,同时设置邮箱路径

vim /etc/dovecot/conf.d/10-ssl.conf 
# SSL/TLS support: yes, no, required. <doc/wiki/SSL.txt>
# disable plain pop3 and imap, allowed are only pop3+TLS, pop3s, imap+TLS and imaps
# plain imap and pop3 are still allowed for local connections
ssl = no vim /etc/dovecot/conf.d/10-auth.conf
# Disable LOGIN command and all other plaintext authentications unless
# SSL/TLS is used (LOGINDISABLED capability). Note that if the remote IP
# matches the local IP (ie. you're connecting from the same computer), the
# connection is considered secure and plaintext authentication is allowed.
# See also ssl=required setting.
disable_plaintext_auth = novim /etc/dovecot/conf.d/10-mail.conf
# See doc/wiki/Variables.txt for full list. Some examples:
#
# mail_location = maildir:~/Maildir
mail_location = mbox:~/mail:INBOX=/var/mail/%u
# mail_location = mbox:/var/mail/%d/%1n/%n:INDEX=/var/indexes/%d/%1n/%n

5.开启Dovecot服务(服务统一在后面开启)

四、创建用户、邮箱、开启服务

1.创建用户

useradd -s /sbin/nologin test 
echo 123456|passwd --stdin test 

2.创建邮箱并设置权限

mkdir -p /home/test/mail/.imap/INBOX
chown -R test.test /home/test

3.开启服务

systemctl enable postfix
systemctl enable dovecot
systemctl enable saslauthdsystemctl restart postfix
systemctl restart dovecot
systemctl restart saslauthd

4.检查端口是否以及在启用(此时监听25、110、143端口)

yum install -y net-tools  #安装TCP/IP工具箱netstat -tnl 
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State      
tcp        0      0 0.0.0.0:25              0.0.0.0:*               LISTEN          
tcp        0      0 0.0.0.0:110             0.0.0.0:*               LISTEN     
tcp        0      0 0.0.0.0:143             0.0.0.0:*               LISTEN   

五、删除用户和邮箱

1.删除普通用户

userdel -r yangwn
#直接删除家目录、邮件目录

2.删除虚拟用户

vi /etc/passwd /etc/shadow /etc/group /etc/gshadow  #虚拟用户在这里删除(有虚拟用户的信息行直接删除)rm -rf /home/test           #删除家目录rm -rf /var/spool/mail/test #删除邮件目录

六、配置域名映射

1.域名解析设置

主机记录  记录类型  线路类型     记录值      优先级 TTL     最后操作时间           操作@	       A	   默认	95.214.177.67	-	600	2020-08-05 01:44:37	修改暂停删除mail	   A	   默认	95.214.177.67	-	600	2020-08-05 01:44:56	修改暂停删除mail	   MX	   默认	swireb.cn.	    5	600	2020-08-05 17:05:49	修改暂停删除

2.本地hosts文件解析设置

C:\WINDOWS\system32\drivers\etc
172.1.1.15 mail.swireb.cn swireb.cn

七、Postfix别名设置

1.Postfix别名简介

#Postfix服务器中可以使用aliases机制属性邮件别名和邮件群发功能,也可以创建用户组,将用户加入某个组中,实现邮件群发
在/etc目录下存在aliases和aliases.db两个文件
aliases是文本文件可以编辑修改
aliases.db是数据库文件,是由aliases文本文件通过命令newaliases生成

2.Postfix别名设置

#设置admin别名组
vim /etc/aliases
admin:          yangwn,test#生成数据库文件
newaliases#修改Postfix配置文件确保邮件别名路径和邮件别名数据库路径已经设置
vim /etc/postfix/main.cf
alias_maps = hash:/etc/aliases
alias_database = hash:/etc/aliases#让别名文件生效
postmap hash:/etc/postfix/access
postalias hash:/etc/aliases#重启sendmail服务
systemctl restart postfix

3.测试发送邮件给别名组

#此时root用户给admin@swireb.cn发送邮件,则会群发到yangwn@swireb.cn和test@swireb.cn邮箱中
echo "This is test Mail"|mail -s "Test Mail Sendmail" admin@swireb.cn#切换用户接受邮件
su - yangwnmail
Heirloom Mail version 12.5 7/5/10.  Type ? for help.
"/var/spool/mail/yangwn": 1 message 1 new
>N  1 root                  Fri Aug  7 14:53  18/565   "Test Mail Sendmail"

八、使用Foxmail客户端进行邮件测试

1.使用Foxmail客户端进行配置
在这里插入图片描述在这里插入图片描述
2.外网发送邮件失败,报RCPT错误(客户端的IP地址不被服务端信任)
在这里插入图片描述
3.查看邮件日志

tail -f /var/log/maillog
Aug  7 13:36:24 mail postfix/smtpd[7910]: connect from unknown[14.205.134.67]
Aug  7 13:36:25 mail postfix/smtpd[7910]: NOQUEUE: reject: RCPT from unknown[14.205.134.67]: 454 4.7.1 <1014575812@qq.com>: Relay access denied; from=<test@swireb.cn> to=<1014575812@qq.com> proto=ESMTP helo=<PC>
Aug  7 13:36:25 mail postfix/smtpd[7910]: disconnect from unknown[14.205.134.67]

4.解决报错问题

#mynetworks参数设置指定受信任SMTP的列表(受信任的SMTP客户端允许通过Postfix传递邮件)
vim /etc/postfix/main.cf
# Alternatively, you can specify the mynetworks list by hand, in
# which case Postfix ignores the mynetworks_style setting.
#
# Specify an explicit list of network/netmask patterns, where the
# mask specifies the number of bits in the network part of a host
# address.
#
# You can also specify the absolute pathname of a pattern file instead
# of listing the patterns here. Specify type:table for table-based lookups
# (the value on the table right-hand side is not used).
#
mynetworks = 0.0.0.0/0
#mynetworks = $config_directory/mynetworks
#mynetworks = hash:/etc/postfix/network_table#重启sendmail服务
systemctl restart sendmail

九、使用mail命令进行邮件测试

1.安装mail命令软件(默认自带)

yum install -y mailx

2.使用mail命令进行邮件发送测试

#发送一份邮件给外网邮箱
echo "This is test Mail"|mail -s "Test Mail Sendmail" 1014575812@qq.com

3.使用mail命令查看邮件

#邮件的保存路径:/var/spool/mail#mail命令默认查看当前用户的邮件(查看其他用户su命令切换后再进行查看)
mail
Heirloom Mail version 12.5 7/5/10.  Type ? for help.
"/var/spool/mail/root": 2 messages  #N代表未读邮件,没有N的代表已读邮件,查看邮件只需输入邮件编号即可
>   1 Mail Delivery Subsys  Thu Aug  6 13:23  71/2753  "Returned mail: see transcript for details"2 杨伟能                 Thu Aug  6 13:38 138/7735  "Re:Test Mail Sendmail"
& helpmail commands
type <message list>             type messages
next                            goto and type next message
from <message list>             give head lines of messages
headers                         print out active message headers #列出邮件标题列表,直接输入h
delete <message list>           delete messages                  #删除指定邮件,例如 d2 d1-2
undelete <message list>         undelete messages
save <message list> folder      append messages to folder and mark as saved  #保存邮件,例如 s 2 /root/mail
copy <message list> folder      append messages to folder without marking them
write <message list> file       append message texts to file, save attachments
preserve <message list>         keep incoming messages in mailbox even if saved
Reply <message list>            reply to message senders
reply <message list>            reply to message senders and all recipients
mail addresses                  mail to specific recipients
file folder                     change to another folder
quit                            quit and apply changes to folder     
xit                             quit and discard changes made to folder
!                               shell escape
cd <directory>                  chdir to directory or home if none given
list                            list names of all available commandsA <message list> consists of integers, ranges of same, or other criteria
separated by spaces.  If omitted, mail uses the last message typed.

十、安装LAMP环境

2.安装指定版本的php

  • 配置拓展yum资源
#安装epel-release
yum install -y epel-release#添加Remi的RPM存储库
rpm -ivh http://rpms.famillecollet.com/enterprise/remi-release-7.rpm#安装yum-config-manager实用程序
yum -y install yum-utils#卸载系统自带的PHP
yum remove php*#查看Yum仓库可以支持安装的php版本
yum list all|grep php
yum search php71
  • 安装指定版本的php5.6
#使用yum-config-manager实用程序指定安装php5.6这个版本
yum-config-manager --enable remi-php56#安装php
yum install -y php#查看PHP版本
php -v
PHP 5.6.40 (cli) (built: Jan 12 2019 13:11:15) 
Copyright (c) 1997-2016 The PHP Group#查询php拓展包
yum search php-opcache
php-opcache.x86_64 : The Zend OPcache
php55-php-opcache.x86_64 : The Zend OPcache
php56-php-opcache.x86_64 : The Zend OPcache
php70-php-opcache.x86_64 : The Zend OPcache
php71-php-opcache.x86_64 : The Zend OPcache
php72-php-opcache.x86_64 : The Zend OPcache
php73-php-opcache.x86_64 : The Zend OPcache
php74-php-opcache.x86_64 : The Zend OPcache
php80-php-opcache.x86_64 : The Zend OPcache#查询php已安装拓展
php -m

3.安装指定版本的mysql

  • 官方文档
#官方文档:https://dev.mysql.com/doc/mysql-yum-repo-quick-guide/en/
  • 安装mysql5.7并初始化
#在CentOS中默认安装有MariaDB,先进行卸载MariaDB
yum remove mariadb*
rpm -qa | grep mariadb #查询是否卸载成功#添加MySQL Yum存储库
https://dev.mysql.com/downloads/repo/yum/下载对应版本的rpm文件并上传至linux系统目录中
wget https://dev.mysql.com/get/mysql80-community-release-el7-3.noarch.rpm#执行下面的命令拓展yum源(任意执行一条命令即可)
rpm -Uvh mysql80-community-release-el7-3.noarch.rpm
yum -y install mysql80-community-release-el7-3.noarch.rpm#查看已启用或禁用了哪些子存储库
yum repolist all|grep mysql
mysql-connectors-community/x86_64  MySQL Connectors Community       启用:    165
mysql-tools-community/x86_64       MySQL Tools Community            启用:    115
mysql55-community/x86_64           MySQL 5.5 Community Server       禁用
mysql55-community-source           MySQL 5.5 Community Server - Sou 禁用
mysql56-community/x86_64           MySQL 5.6 Community Server       禁用
mysql56-community-source           MySQL 5.6 Community Server - Sou 禁用
mysql57-community/x86_64           MySQL 5.7 Community Server       禁用
mysql57-community-source           MySQL 5.7 Community Server - Sou 禁用
mysql80-community/x86_64           MySQL 8.0 Community Server       启用:    193
mysql80-community-source           MySQL 8.0 Community Server - Sou 禁用#安装yum配置管理工具
yum -y install yum-utils#禁用8.0系列的子存储库并启用5.7系列的子存储库
yum-config-manager --disable mysql80-community
yum-config-manager --enable mysql57-community#安装mysql
yum install -y mysql-community-server#启动mysql服务
systemctl enable mysqld
systemctl restart mysqld#查看mysql版本
mysql --help|grep Distrib#查看mysql始化密码
grep 'temporary password' /var/log/mysqld.log
2020-08-07T12:35:37.492461Z 1 [Note] A temporary password is generated for root@localhost: Enb*.bZB-1cW#修改mysql用户root的密码
mysqladmin -uroot -p password
Enter password:
New password:
Confirm new password:#刷新权限
mysql> flush privileges; 
Query OK, 0 rows affected (0.00 sec)#退出mysql
mysql> exit
Bye
  • 修改mysql密码策略
#查看密码策略
mysql> show VARIABLES like "%password%";
+----------------------------------------+-----------------+
| Variable_name                          | Value           |
+----------------------------------------+-----------------+
| default_password_lifetime              | 0               |
| disconnect_on_expired_password         | ON              |
| log_builtin_as_identified_by_password  | OFF             |
| mysql_native_password_proxy_users      | OFF             |
| old_passwords                          | 0               |
| report_password                        |                 |
| sha256_password_auto_generate_rsa_keys | ON              |
| sha256_password_private_key_path       | private_key.pem |
| sha256_password_proxy_users            | OFF             |
| sha256_password_public_key_path        | public_key.pem  |
| validate_password_check_user_name      | OFF             |
| validate_password_dictionary_file      |                 |
| validate_password_length               | 8               |
| validate_password_mixed_case_count     | 1               |
| validate_password_number_count         | 1               |
| validate_password_policy               | MEDIUM          |
| validate_password_special_char_count   | 1               |
+----------------------------------------+-----------------+
17 rows in set (0.01 sec)#方法一:修改密码策略
vim /etc/my.cnf  
validate_password=off #设置简单密码systemctl restart mysqld  #重启mysql服务#方法二:修改密码策略
mysql> set global validate_password_policy=0; #更改密码策略为LOW
mysql> set global validate_password_length=0; #更改密码长度

4.安装Apache

#安装Apache
yum install -y httpd httpd-devel httpd-tools#启动Apache服务
systemctl enable httpd
systemctl restart httpd

十一、Postfixadmin配置

1.PostfixAdmin简介

PostfixAdmin是一个基于Web的界面,用于为许多用户配置和管理基于Postfix的电子邮件服务器。配置要求:LAMP/LNMP/LEMP环境,同时需要PHP5.4版本以上

2.下载PostfixAdmin软件并解压

#下载地址:https://sourceforge.net/projects/postfixadmin/files/
#下载地址:https://github.com/postfixadmin/postfixadmin
wget https://nchc.dl.sourceforge.net/project/postfixadmin/postfixadmin/postfixadmin-3.2/postfixadmin-3.2.tar.gz#下载上传到linux并解压到Apache发布目录/var/www/html/下
tar xzf postfixadmin-3.2.tar.gz -C /var/www/html/#重命名目录名称
mv /var/www/html/postfixadmin-3.2 /var/www/html/postfixadmin#设置Apache发布目录/var/www/html/权限
chown -R root.root /var/www/html/
chmod -R 777 /var/www/html/postfixadmin

3.访问PostfixAdmin介绍页面:http://mail.swireb.cn/postfixadmin/public
在这里插入图片描述
4.访问PostfixAdmin安装检查页面:http://mail.swireb.cn/postfixadmin/public/setup.php
在这里插入图片描述
5.检查页面相关报错解决

#报错一:Please edit config.inc.php - change $CONF['configured'] to true after setting your database settings
vim /var/www/html/postfixadmin/config.inc.php* You have to set $CONF['configured'] = true; before the* application will run!* Doing this implies you have changed this file as required.* i.e. configuring database etc; specifying setup.php password etc.*/
$CONF['configured'] = true;#报错二:ERROR: the templates_c directory doesn't exist or isn't writeable for the webserver
mkdir -p /var/www/html/postfixadmin/templates_c
chmod -R 777 /var/www/html/postfixadmin/templates_c

6.检查页面提示创建数据库、安装php拓展
在这里插入图片描述

#使用root用户登录数据
mysql -uroot -p#创建postfix的数据库并且字符集设置为utf8
mysql> create database postfix charset=utf8;
Query OK, 1 row affected (0.00 sec)#设置数据库的用户名和密码
mysql> grant all on *.* to postfix@'localhost' identified by "postfix";
Query OK, 0 rows affected, 1 warning (0.00 sec)#刷新权限
mysql> flush privileges; 
Query OK, 0 rows affected (0.00 sec)#显示全部数据库
mysql> show  databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| postfix            |
| sys                |
+--------------------+
5 rows in set (0.00 sec)#删除数据库
mysql> drop database postfix;
Query OK, 0 rows affected (0.00 sec)#退出mysql
mysql> exit
Bye
#按照报错安装php拓展
yum install -y php-mysql php-mbstring php-imap php-config

7.修改PostfixAdmin配置文件连接数据库

vim /var/www/html/postfixadmin/config.inc.php
$CONF['database_type'] = 'mysqli';
$CONF['database_host'] = 'localhost';
$CONF['database_user'] = 'postfix';
$CONF['database_password'] = 'postfix';
$CONF['database_name'] = 'postfix';

8.访问PostfixAdmin安装检查页面:http://mail.swireb.cn/postfixadmin/public/setup.php并设置安装密码

Setup password:abc123%%

在这里插入图片描述

9.将随机生成的安装密码写入PostfixAdmin配置文件中

#按照提示将安装密码写入配置文件(不要刷新网页,随机密码会改变)
vim /var/www/html/postfixadmin/config.inc.php
// In order to setup Postfixadmin, you MUST specify a hashed password here.
// To create the hash, visit setup.php in a browser and type a password into the field,
// on submission it will be echoed out to you as a hashed value.
// $CONF['setup_password'] = 'changeme'; #注释原有的信息,将网页的随机密码写入
$CONF['setup_password'] = 'df7e381c1d9b16d15936d8b118510c5e:1fdc33ebe6cf8b60c6c25641d6f196772b3a8847';

在这里插入图片描述

10.设置超级管理员账户、密码

Setup password:abc123%%
Admin:root@swireb.cn	
Password:abc123%%

在这里插入图片描述

11.访问PostfixAdmin管理员登录页面:http://mail.swireb.cn/postfixadmin/public/login.php
在这里插入图片描述

12.访问PostfixAdmin普通登录页面:http://mail.swireb.cn/postfixadmin/public/users/login.php
在这里插入图片描述

十二、部署RoundCube

1.RoundCube简介

供一个e-mail客户端应该具备的所有功能包括MIME支持,地址薄,文件夹操作,信息搜索和拼写检查。配置要求:LAMP/LNMP/LEMP环境,同时需要PHP5.4版本以上

2.下载RoundCube软件并解压

#下载地址:https://roundcube.net/download/
wget https://github.com/roundcube/roundcubemail/releases/download/1.4.7/roundcubemail-1.4.7-complete.tar.gz#下载上传到linux并解压到Apache发布目录/var/www/html/下
tar xzf roundcubemail-1.4.7-complete.tar.gz -C /var/www/html/#重命名目录名称
mv /var/www/html/roundcubemail-1.4.7 /var/www/html/roundcubemail#设置Apache发布目录/var/www/html/权限
chown -R root.root /var/www/html/
chmod -R 775 /var/www/html/roundcubemail

3.php相关设置

#安装php拓展
yum -y install php-xml php-ldap php-gd php-pecl-imagick #修改php的时区为中国
vim /etc/php.ini 
[Date]
; Defines the default timezone used by the date functions
; http://php.net/date.timezone
date.timezone = PRC#重启Apache服务
systemctl restart httpd

4.访问RoundCube安装页面:http://mail.swireb.cn/roundcubemail/installer/index.php
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

5.创建数据库

mysql -uroot -p#创建postfix的数据库并且字符集设置为utf8
mysql> create database roundcubemail charset=utf8;
Query OK, 1 row affected (0.00 sec)#设置数据库的用户名和密码
mysql> grant all on *.* to roundcube@'localhost' identified by "roundcube";
Query OK, 0 rows affected, 1 warning (0.00 sec)#刷新权限
mysql> flush privileges; 
Query OK, 0 rows affected (0.00 sec)#显示全部数据库
mysql> show  databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| postfix            |
| roundcubemail      |
| sys                |
+--------------------+
6 rows in set (0.00 sec)#删除数据库
mysql> drop database roundcubemail;
Query OK, 0 rows affected (0.00 sec)#退出mysql
mysql> exit
Bye

在这里插入图片描述
6.设置IMAP、SMTP连接服务器的域名和端口
在这里插入图片描述
在这里插入图片描述
7.设置语言为中文
在这里插入图片描述
8.安装插件可选
在这里插入图片描述

9.生成配置文件,并上传到/var/www/html/roundcubemail/config/目录下
在这里插入图片描述
在这里插入图片描述
10.修改日志目录和临时目录的权限为777
在这里插入图片描述

cd /var/www/html/roundcubemailchmod -R 777 temp/ logs/

12.初始化数据库
在这里插入图片描述
13.测试邮件发送,要先配置postfix支持SMTP

vim /etc/postfix/main.cf
#开启SMTP认证
smtpd_sasl_auth_enable = yes
smtpd_sasl_local_domain = 'mail.swireb.cn'
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

在这里插入图片描述14.访问RoundCube登录页面:http://mail.swireb.cn/roundcubemail/

#配置Dovecot支持重定向登录(可以使用yangwn用户登录,也可以使用yangwn@swireb.cn用户登录)
vim /etc/dovecot/dovecot.conf
auth_username_format = %n#重启Dovecot服务
systemctl restart  dovecot

在这里插入图片描述
15.RoundCube禁止访问安装文件

#将安装目录设置为600的权限
chmod -R 600 /var/www/html/roundcubemail/installer

在这里插入图片描述
16.开启自动创建邮箱目录的功能

#Dovecot服务开启自动创建邮箱目录
vim /etc/dovecot/conf.d/20-imap.conf 
#imap_fetch_failure = disconnect-immediatelyprotocol imap {# Space separated list of plugins to load (default is global mail_plugins).
mail_plugins = $mail_plugins autocreate  #开启自动创建邮箱目录# Maximum number of IMAP connections allowed for a user from each IP address.# NOTE: The username is compared case-sensitively.#mail_max_userip_connections = 10
}
#要创建的目录列表
plugin {autocreate     = Trashautocreate2    = Junkautocreate3    = Draftsautocreate4    = Sentautosubscribe  = Trashautosubscribe2 = Junkautosubscribe3 = Draftsautosubscribe4 = Sent}
#重启Dovecot服务
systemctl restart  dovecot

在这里插入图片描述