返回列表 发帖

CentOS6_安装与配置邮件服务器(Postfix+Dovecot+SquirrelMail)

实验中,邮件服务器的信息:
[root@mail ~]# cat /etc/redhat-release
CentOS release 6.9 (Final)
[root@mail ~]# uname -r
2.6.32-696.el6.x86_64

[root@mail ~]# hostname
mail.zhuohua.store
[root@mail ~]# cat /etc/sysconfig/network
NETWORKING=yes
HOSTNAME=mail.zhuohua.store


[root@mail ~]# ifconfig
eth0      Link encap:Ethernet  HWaddr 00:0C:29:2B:17:3A  
          inet addr:192.168.168.131  Bcast:192.168.168.255  Mask:255.255.255.0
          inet6 addr: fe80::20c:29ff:fe2b:173a/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:679 errors:0 dropped:0 overruns:0 frame:0
          TX packets:288 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:53826 (52.5 KiB)  TX bytes:33203 (32.4 KiB)

lo        Link encap:Local Loopback  
          inet addr:127.0.0.1  Mask:255.0.0.0
          inet6 addr: ::1/128 Scope:Host
          UP LOOPBACK RUNNING  MTU:65536  Metric:1
          RX packets:0 errors:0 dropped:0 overruns:0 frame:0
          TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0
          RX bytes:0 (0.0 b)  TX bytes:0 (0.0 b)

[root@mail ~]#



卸载Senmail:
[root@mail ~]# yum -y remove sendmail

设置默认MTA:
[root@mail ~]# alternatives --config mta



安装Postfix和Dovecot:
[root@mail ~]# yum -y install postfix dovecot


开机自动运行Postfix:
[root@mail ~]# chkconfig --level 35 postfix on
[root@mail ~]#

开机自动运行Dovecot:
[root@mail ~]# chkconfig --level 35 dovecot on
[root@mail ~]#


查看Postfix的版本:
[root@mail ~]# rpm -q postfix
postfix-2.6.6-8.el6.x86_64

查看Dovecot的版本:
[root@mail ~]# rpm -q dovecot
dovecot-2.0.9-22.el6.x86_64


建立用户模板下的邮箱目录,以便于建立新用户时,相应用户的邮箱目录自动被建立:(Postfix用户的邮件文件都会在自己家目录的Maildir文件夹里)
[root@mail ~]# mkdir /etc/skel/Maildir
[root@mail ~]#



######

配置Postfix:
[root@mail ~]# vi /etc/postfix/main.cf

#myhostname = host.domain.tld
修改为:(设置为系统的主机名)
myhostname = mail.zhuohua.store

#mydomain = domain.tld
修改为:(设置域名,此处设置将成为E-mail地址“@”后面的部分)
mydomain = zhuohua.store

#myorigin = $mydomain
修改为:
myorigin = $mydomain

inet_interfaces = localhost
修改为:(接受来自任意网络的请求)
inet_interfaces = all

mydestination = $myhostname, localhost.$mydomain, localhost
修改为:( 指定发给本地邮件的域名 )
mydestination = $myhostname, localhost.$mydomain, localhost, $mydomain

#mynetworks = 168.100.189.0/28, 127.0.0.0/8
修改为:
mynetworks = 127.0.0.0/8

#home_mailbox = Maildir/
修改为:( 指定用户邮箱目录 )
home_mailbox = Maildir/

#relay_domains = $mydestination
修改为:( 定义允许转发的域名  )
relay_domains = $mydestination

#smtpd_banner = $myhostname ESMTP $mail_name ($mail_version)
修改为:( 不显示SMTP服务器的相关信息 )
smtpd_banner = $myhostname ESMTP unknow

追加:
smtpd_sasl_type = dovecot
smtpd_sasl_path = private/auth
smtpd_sasl_auth_enable = yes
smtpd_sasl_local_domain = $myhostname
smtpd_sasl_security_options = noanonymous

smtpd_recipient_restrictions = permit_mynetworks, permit_sasl_authenticated, reject_unauth_destination

smtpd_sasl_security_restrictions = permit_mynetworks, permit_sasl_authenticated, reject_unauth_destination

#规定单封邮件的最大容量大概为80MB,以字节为单位:(包括附件)
message_size_limit = 80000000

#不限制单个用户邮箱的大小:
mailbox_size_limit = 0


保存文件退出后,重启Postfix:
[root@mail ~]# service postfix restart
关闭 postfix:[确定]
启动 postfix: [确定]
[root@mail ~]#


查看有关邮箱、邮件的限制:
/usr/sbin/postconf |grep size_limit
图片2.png



######

配置Dovecot:
[root@mail ~]# vi /etc/dovecot/dovecot.conf

#protocols = imap pop3 lmtp
修改为:
protocols = imap pop3 lmtp

#listen = *, ::
修改为:
listen = *, ::



######

配置认证方式:
[root@mail ~]# vi /etc/dovecot/conf.d/10-auth.conf

#disable_plaintext_auth = yes
修改为:
disable_plaintext_auth = no

auth_mechanisms = plain
修改为:
auth_mechanisms = plain login



######

配置邮箱文件夹:
[root@mail ~]# vi /etc/dovecot/conf.d/10-mail.conf

#   mail_location = maildir:~/Maildir
修改为:
mail_location = maildir:~/Maildir



######

配置认证:
[root@mail ~]# vi /etc/dovecot/conf.d/10-master.conf

  unix_listener auth-userdb {
    #mode = 0600
    #user =
    #group =
  }
修改为:
#  unix_listener auth-userdb {
    #mode = 0600
    #user =
    #group =
#  }

  # Postfix smtp-auth
  #unix_listener /var/spool/postfix/private/auth {
  #  mode = 0666
  #}
修改为:
  # Postfix smtp-auth
   unix_listener /var/spool/postfix/private/auth {
    mode = 0666
    user = postfix
    group = postfix
}


禁用SSL:
[root@mail ~]# vi /etc/dovecot/conf.d/10-ssl.conf

#ssl = yes
修改为:
ssl = no



######

配置POP3:
[root@mail ~]# vi /etc/dovecot/conf.d/20-pop3.conf

#pop3_uidl_format = %08Xu%08Xv
修改为:
pop3_uidl_format = %08Xu%08Xv

#pop3_client_workarounds =
修改为:
pop3_client_workarounds = outlook-no-nuls oe-ns-eoh


保存文件退出后,重启Dovecot:
[root@mail ~]# service dovecot restart
停止 Dovecot Imap:[确定]
正在启动 Dovecot Imap:[确定]
[root@mail ~]#


确认Dovecot正在运行中:
[root@mail ~]# service dovecot status
dovecot (pid  2470) 正在运行...
[root@mail ~]#

确认Postfix正在运行中:
[root@mail ~]# service postfix status
master (pid  2358) 正在运行...
[root@mail ~]#



######

插入防火墙规则:( 打开TCP 25、110、143端口 )
iptables -I INPUT -p tcp -m multiport --dport 25 -j ACCEPT
iptables -I INPUT -p tcp -m multiport --dport 110 -j ACCEPT
iptables -I INPUT -p tcp -m multiport --dport 143 -j ACCEPT

保存防火墙netfilter的规则:
[root@mail ~]# iptables-save > /etc/sysconfig/iptables
[root@mail ~]#


查看防火墙netfilter的配置文件:
[root@mail ~]# cat /etc/sysconfig/iptables
# Generated by iptables-save v1.4.7 on Thu Jul  5 05:21:44 2018
*filter
:INPUT ACCEPT [0:0]
:FORWARD ACCEPT [0:0]
:OUTPUT ACCEPT [4:432]
-A INPUT -p tcp -m multiport --dports 143 -j ACCEPT
-A INPUT -p tcp -m multiport --dports 110 -j ACCEPT
-A INPUT -p tcp -m multiport --dports 25 -j ACCEPT

-A INPUT -m state --state RELATED,ESTABLISHED -j ACCEPT
-A INPUT -p icmp -j ACCEPT
-A INPUT -i lo -j ACCEPT
-A INPUT -p tcp -m state --state NEW -m tcp --dport 22 -j ACCEPT
-A INPUT -j REJECT --reject-with icmp-host-prohibited
-A FORWARD -j REJECT --reject-with icmp-host-prohibited
COMMIT
# Completed on Thu Jul  5 05:21:44 2018
[root@mail ~]#

注释:
Postfix使用TCP 25端口;
Dovecot使用TCP 110、143端口;





######

创建Postfix用户:(其实就是系统用户,但不需要登录操作系统)

先创建Postfix用户组:
groupadd mailusers

用户密码就是邮箱登录密码:
adduser -g mailusers -s /sbin/nologin zhuohua
echo '111' | passwd --stdin zhuohua

注释:邮箱帐号为zhuohua@zhuohua.store

###

adduser -g mailusers -s /sbin/nologin happy
echo '222' | passwd --stdin happy

注释:邮箱帐号为happy@zhuohua.store


######

客户端使用Foxmail连接邮件服务器:
图片3.png

在Foxmail中创建邮箱帐号zhuohua@zhuohua.store:
图片4.png

笺注: 192.168.168.131 为邮件服务器的IP地址。


依此类推,再在Foxmail中创建邮箱帐号happy@zhuohua.store:
图片5.png

笺注: 要先在邮件服务器上创建Postfix用户。



实验中,zhuohua@zhuohua.store和happy@zhuohua.store可以互相发送、接收邮件,包括附件。

zhuohua@zhuohua.store给happy@zhuohua.store发送邮件:
图片6.png

happy@zhuohua.store接收到邮件:
图片7.png



######

Postfix用户的邮件文件都在自己家目录的Maildir文件夹里,但无法直接看见邮件内容和附件。
图片8.png

图片9.png

备注:

cur目录存放已读邮件,new目录存放未读邮件。

Foxmail客户端、SquirrelMail收取到的邮件都会视为已读。

邮件会在邮件服务器、Foxmail客户端各保留一份,就算在Foxmail客户端把邮件删除了,服务器上的那份还是在的。

在SquirrelMail把邮件删除了,就等于在邮件服务器删除了。

可以手动删除cur目录里的文件的。


使用Foxmail客户端发送邮件后,在邮件服务器上,邮件的附件只会放在收件人的邮箱目录里,发件人的邮箱目录是不会保留的;

使用SquirrelMail发送邮件后,在邮件服务器上,邮件的附件会同时放在发件人和收件人的邮箱目录里;













######
######

在邮件服务器中安装SquirrelMail:

关闭SELinux:
setenforce 0
sed -i 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/selinux/config


需要先搭建好LAMP环境:(使用本地光盘作为Yum源即可)
yum -y install httpd php php-mysql mysql mysql-server net-snmp-utils gcc-c++ vim patch php-mysql php-gd php-ldap php-odbc php-pear php-xml php-xmlrpc


修改Apache的主配置文件:
sed -i 's/DirectoryIndex index.html index.html.var/DirectoryIndex index.html index.php index.html.var/g' /etc/httpd/conf/httpd.conf

sed -i 's/#ServerName www.example.com:80/ServerName www.example.com:80/g' /etc/httpd/conf/httpd.conf


修改PHP的主配置文件:
sed -i 's/;date.timezone =/date.timezone = PRC/g' /etc/php.ini



启动Apache:
service httpd start
chkconfig --level 35 httpd on

查看Apache的版本:
[root@mail ~]# httpd -v
Server version: Apache/2.2.15 (Unix)
Server built:   Mar 22 2017 06:52:55
[root@mail ~]#


启动MySQL:(其实用不着MySQL)
service mysqld start
chkconfig --level 35 mysqld on

查看MySQL的版本:
[root@mail ~]# mysql -V
mysql  Ver 14.14 Distrib 5.1.73, for redhat-linux-gnu (x86_64) using readline 5.1
[root@mail ~]#



插入防火墙规则:( 打开TCP 80端口 )
[root@mail ~]# iptables -I INPUT -p tcp --dport 80 -j ACCEPT
[root@mail ~]# iptables-save > /etc/sysconfig/iptables
[root@mail ~]#



######

SquirrelMail是一套基于标准的、采用PHP4开发的l邮件系统,内置纯PHP支持的IMAP和SMTP协议,所有页面遵循HTML4.0标准(没有使用JavaScript支持),以便最大限度兼容更多浏览器上。
它对系统要求非常低,并且安装和配置非常容易。SquirrelMail具备一个客户端邮件程序所应拥有的一切功能,包括支持增强型的MIME、地址薄、文件夹操作等等功能。


下载小松鼠包:https://pan.baidu.com/s/1aui5Dm_Kk1_CuFIjccBvGA   提取码:1od0
下载汉化语言包:https://pan.baidu.com/s/1WzFZhMTPr3aJj3rO_ruH8w   提取码:rt16


安装小松鼠包与汉化语言包:

tar -zxvf squirrelmail-webmail-1.4.22.tar.gz
tar -zxvf all_locales-1.4.18-20090526.tar.gz -C squirrelmail-webmail-1.4.22
cp -rv squirrelmail-webmail-1.4.22 /var/www/html/mail

cd /var/www/html/mail
mkdir attach
chown -R apache:apache attach/ data/

修改配置文件:
cd config
cp config_default.php config.php

[root@mail config]# vi config.php
修改:
$domain = 'zhuohua.store';  #设置域名
$imap_server_type = 'dovecot';

$data_dir = '/var/www/html/mail/data/';
$attachment_dir = '/var/www/html/mail/attach/';

$squirrelmail_default_language = 'zh_CN';
$default_charset = 'zh_CN.UTF-8';


保存文件退出后,重启Apache:
[root@mail ~]# service httpd restart
停止 httpd:[确定]
正在启动 httpd:[确定]
[root@mail ~]#



###

在浏览器上使用zhuohua@zhuohua.store登录SquirrelMail:
http://192.168.168.131/mail/
图片1.png


happy@zhuohua.store在Foxmail客户端给zhuohua@zhuohua.store发送邮件后,zhuohua@zhuohua.store在SquirrelMail是可以收到邮件(包括附件):
图片2.png

图片3.png


###

使用zhuohua@zhuohua.store给happy@zhuohua.store发送测试邮件:
图片4.png

可以加上附件:
图片5.png

备注:
默认情况下,在SquirrelMail发送的附件的单个大小,或多个附件的总量大小,都不得大于2MB


happy@zhuohua.store也可以接收到邮件(包括附件):
图片6.png



###

解决在SquirrelMail发送附件大小的限制:(其实这是PHP的限制)

查看PHP的版本:
[root@mail ~]# php -v
PHP 5.3.3 (cli) (built: Mar 22 2017 12:27:09)
Copyright (c) 1997-2010 The PHP Group
Zend Engine v2.3.0, Copyright (c) 1998-2010 Zend Technologies
[root@mail ~]#


修改PHP的主配置文件:
[root@mail ~]# vi /etc/php.ini

upload_max_filesize = 2M
修改为:
upload_max_filesize = 80M

post_max_size = 8M
修改为:
post_max_size = 85M


保存文件退出后,重启Apache:
[root@mail ~]# service httpd restart
停止 httpd:[确定]
正在启动 httpd:[确定]
[root@mail ~]#


现在,在SquirrelMail里可上传的附件量变大了:
图片7.png





######

以下设置邮件组:

增加组名:(无需去创建一个系统用户组)

[root@mail ~]# echo 'team_caiwu:zhuohua,happy' >> /etc/aliases
[root@mail ~]#

[root@mail ~]# tail -1 /etc/aliases
team_caiwu:zhuohua,happy
[root@mail ~]#


生成hash数据库文件:
[root@mail ~]# newaliases
[root@mail ~]#


在邮件服务器中创建第三个Postfix用户:
adduser -g mailusers -s /sbin/nologin jacky
echo '888' | passwd --stdin jacky

注释:
邮箱帐号为jacky@zhuohua.store
用户密码就是邮箱登录密码


使用jacky@zhuohua.store在SquirrelMail发送群邮件:
图片8.png


撰写邮件,收件人: team_caiwu@zhuohua.store
图片9.png

邮箱帐号zhuohua@zhuohua.store、happy@zhuohua.store在SquirrelMail都可以收到群发邮件(包括附件):
图片10.png

笺注:
邮箱帐号zhuohua@zhuohua.store、happy@zhuohua.store在Foxmail客户端都可以收到群发邮件(包括附件)





相关文章:
Cacti设置告警邮件
Nagios设置告警邮件

CentOS8_安装与配置邮件服务器(Postfix+Dovecot)





#################################
#################################
亲,学习研究也要劳逸结合哦,来我微店逛逛,买点东西好好犒劳犒劳自己和家人吧^_^^_^


旖旎澳洲|香浓夏果;包邮【七猩猩_夏威夷果207g*2袋】奶油味 澳洲进口坚果休闲食品,颗粒大奶味足,送开果器
xianweiyi.png

FaSoLa内衣收纳盒三件套 文胸内裤袜子收纳箱有盖整理箱储物
neiyi.png

FaSoLa日式 沥水架 大号塑料厨房 碗碟沥水置物架 厨房角架 碗架
lishui.png

苏泊尔电磁炉火锅家用智能正品学生电池炉灶特价炒菜
su.png

透明文字包中包潮酷风范透明时尚女包斜挎单肩手提包SN-8925
bao.png

返回列表