Linux邮件服务器软件-postfix的安装及配置
0X01- 准备工作
1. 为邮件服务器添加DNS解析
虽然不加DNS解析也能把邮件发出去,但会被大多数邮件服务器当作垃圾邮件。根据我们的实际经验,需要添加三条DNS解析记录:A记录、MX记录、TXT记录
2. 准备存放邮件的硬盘空间
如果用的是阿里云入门级Linux服务器,有一块20G的数据盘未挂载,需要格式化并挂载(假设这里挂载的目录是/data)
3、这里以下面为例
企业域名 benet.com
邮件服务器 mail.benet.com
Mail服务器名: mail.benet.com
0X02- postfix、sasl2 、dovecot安装
1 [root@mail ~]# rpm-qa dovecot //先检测dovecot软件包是否已经安装 2 [root@mail ~]# yum install postfix cyrus-sasl* dovecot //安装Postfix、sasl2 、dovecot,如果是debain则使用apt-get install
0X03- 配置postfix
postfix是CentOS默认安装的邮件服务器软件。以下配置示例假设要配置的域名是benet.com邮件服务器主机名是mail.benet.com。
1. 打开postfix的配置文件
1 [root@mail ~]# vi /etc/postfix/main.cf
2. :75 光标移至第75行,修改myhostname
myhostname = mail.benet.com
3. :83 光标移至第83行,修改mydomain
mydomain = benet.com
4. :99 光标移至第99行,修改myorigin
myorigin = $mydomain
5. :116光标移至第116行,修改inet_interfaces
inet_interfaces = all
6. :119光标移至第119行,修改inet_protocols
inet_protocols = ipv4
7. :164光标移至第164行,添加$mydomain
mydestination = $myhostname,localhost.$mydomain, localhost, $mydomain
8. :251光标移至第251行,修改mynetworks
mynetworks_style = subnet //指定全网IP,这两个参数设置非常重要(下面)
9. :264光标移至第264行,修改mynetworks
mynetworks =0.0.0.0/0,127.0.0.0/8 //表示全部网络地址可以访问邮件
子网掩码(netmask)转换器:Network and IP address calculator
10. :419 光标移至第419行,设置home_mailbox
home_mailbox = Maildir/ //如果采用系统帐号作为邮件用户名,该目录为帐号下的目录最后面添加(sasl加密算法支持)
11. :425 光标移至第425行,设置mail_spool_directory,/data是之前挂载的数据盘,mail目录需要通过mkdir命令创建
mail_spool_directory = /data/mail //没有挂载盘的话,mail_spool_directory = /var/mail
12. 在文件最后增加以下内容
smtpd_sasl_auth_enable = yes smtpd_sasl_security_options = noanonymous broken_sasl_auth_clients = yes smtpd_recipient_restrictions =permit_sasl_authenticated,reject_unauth_destination,permit_mynetworks smtpd_client_restrictions =permit_sasl_authenticated
13. 重启postfix使设置生效
1 [root@mail ~]#service postfix restart
0X04- dovecot 部分安装
1. 从命令行选择可用的 MTA
1 [root@mail ~]#alternatives --config mta
2. 修改系统帐号验证
1 [root@mail ~]#vi /etc/sysconfig/saslauthd
SOCKETDIR=/var/run/saslauthd MECH=shadow //采用系统帐号验证
4. 修改或者添加
1 [root@mail ~]#vi /etc/sasl2/smtpd.conf
pwcheck_method: saslauthd mech_list: plain login log_level:3
5. 修改或者添加
1 [root@mail ~]# vi /etc/dovecot/dovecot.conf
protocols = imap pop3
listen = *
6. Dovecot 配置 dovecot.conf 文件配置邮件接收的存储位置,要和postfix配置目录一致
1 [root@mail ~]# vi /etc/dovecot/conf.d/10-mail.conf
去掉下面一行注释
mail_location = maildir:~/Maildir
0X05- 重新启动程序
1 [root@mail ~]# /etc/init.d/postfix restart //或者service postfix restart
2 [root@mail ~]# /etc/init.d/dovecot restart //或者service dovecot restart
3 [root@mail ~]# /etc/init.d/saslauthd restart //或者service saslauthd restart
0X06- 测试流程
发外网邮箱
1 [root@mail ~]# echo "Hello World" | sendmail "收件邮箱“
建立测试账号
1 [root@mail ~]#useradd qwer -s /sbin/nologin //建立用户qwer 2 [root@mail ~]#useradd abcd -s /sbin/nologin //建立用户abcd 3 [root@mail ~]#echo 'qwer1234' | passwd --stdin qwer //为qwer设立密码 4 [root@mail ~]#echo 'abcd1234' | passwd --stdin abcd //为abcd设立密码
发信息
1 [root@mail ~]#telnet 域名/127.0.0.1 25 2 helo mail.benet.com 3 mail from:qwer@benet.com 4 rcpt to:abcd@benet.com 5 data 6 message 7 . 8 quit
收信息
1 [root@mail ~]#telnet 域名/127.0.0.1 110 2 user 用户名 3 pass 密码 4 list 5 retr 1 6 quit
0X07- 设置开机自动启动 (按需)
1 [root@mail ~]# chkconfig –level 345 postfixon
2 [root@mail ~]# chkconfig –level 345 dovecoton
3 [root@mail ~]# chkconfig –level 345saslauthd on
0X08- 设置开机自动启动 (按需)
(1)先新建系统帐号
1 [root@mail ~]# useradd -s /sbin/nologin -m zhangsan 2 [root@mail ~]# passwd test //密码 test
邮件存放目录
/home/pay/Maildir
(2)添加邮箱账号
1 [root@mail ~]#/usr/sbin/testsaslauthd -u zhangsan -p test
上面这步所使用的用户名和密码,系统中必须有该用户和对应的密码,否则会报错
返回:ok,successd,执行成功。
如果遇到问题:
vi /etc/sysconfig/saslauthd
#MECH=pam
改成:
MECH=shadow
FLAGS=
然后重启saslauthd: service saslauthd restart
再来测试 /usr/sbin/testsaslauthd –u myuserid –p ‘mypassword’ //这里的账号和密码要换成你的linux 的用户名和密码
0: OK "Success."
0X09- foxmail 测试
添加账号:pop3 stmp 都需要设置为域名地址(mail.benet.com)
最后就可以通过outlook,foxmail等客户端测试邮件服务器了。
用foxmail连接我设置的这个内网的服务器,发现最后测试邮箱配置的时候,竟然提示这样的错误:-ERR Plaintext authentication disallowed on non-secure (SSL/TLS) connections。导致接收邮件测试失败。于是百度了这个问题,终于找到了无法接收外网服务器的设置。
修改方法如下:
vi /etc/dovecot/conf.d/10-auth.conf
去掉disable_plaintext_auth前面#,修改为disable_plaintext_auth = no
vi
/etc/dovecot/conf.d/10-ssl.conf
修改为ssl = no
重启dovecot服务
service dovecot restart
OK了,再用foxmail测试,终于成功了,可以顺利接收外网发来的邮件了。
完全正常后删除测试邮箱,以免存在系统漏洞。
userdel –r test
userdel –f test
postconf –d message_size_limit 显示默认邮件大小
修改邮件附件发送大小限制
/etc/postfix/main.cf
message_size_limit = 20480000
0X10- 常见问题
testsaslauthd出现0: NO "authentication failed"错误提示的解决办法
在停止sendmail服务: service sendmail stop 或者: /etc/rc.d/init.d/sendmail stop 后卸载掉sendmail: rpm -e sendmail
后安装了postfix yum -y installpostfix。
配置好main.cf
安装 cyrus-sasl 软件包: yum -y install cyrus-sasl*
安装SMTP认证组件:yum install -y dovecot saslauthd*
运行saslauth
saslauthd -v
#如果显示类似authenticationmechanisms:getpwent pam shadow则可显示saslauthd支持的认证机制
编辑/etc/sysconfig/saslauthd文件,
vim /etc/sysconfig/saslauthd
#确认其为MECH=pam
启动saslauthd service saslauthdstart
运行:
/usr/sbin/testsaslauthd –u user –p‘password’
这时总是出错:0: NO "authentication failed"
该怎么办呢?
其实很简单:vi /etc/sysconfig/saslauthd
#MECH=pam
改成:
MECH=shadow
FLAGS=
然后重启saslauthd: service saslauthd restart

浙公网安备 33010602011771号