centos7 postfix + dovecot 2020年全网最薪最完整版本

环境:centos 7 x64

    因为我这台服务器已经安装了lnmp环境,所以网上哪些要纯净的centos的教程都不适合,还有centos 6 跟centos 7是不一样的哦,防火墙开启,用户验证都跟centos7不一样的,本文是centos7 x64下搭建的邮件服务器,博主在搭建的过程中踩过无数的坑,别说为了后人少踩坑,就是为了我自己苦逼的这天写这篇文章记录一下也是很有意义的。

  目前我知道的国内厂商阿里云的服务器,可以直接放弃看文章了,vultr的也是。

登录到服务器的第一件事情是:(这个是我上传下载文件习惯用的工具)

yum -y install vim telnet bind-utils lrzsz

查看下这台服务器能不能连接国内常用的邮箱,不能的话那就换服务器吧

telnet smtp.163.com 25
telnet smtp.qq.com 587

开放常用的邮件端口:

centos 7开启常用的邮件端口
firewall-cmd --add-port=25/tcp --permanent
firewall-cmd --add-port=80/tcp --permanent
firewall-cmd --add-port=110/tcp --permanent
firewall-cmd --add-port=143/tcp --permanent
firewall-cmd --add-port=465/tcp --permanent
firewall-cmd --add-port=587/tcp --permanent
firewall-cmd --add-port=993/tcp --permanent
firewall-cmd --add-port=995/tcp --permanent

centos 6开启常用的邮件端口
/sbin/iptables -I INPUT -p tcp --dport 25 -j ACCEPT
/sbin/iptables -I INPUT -p tcp --dport 80 -j ACCEPT
/sbin/iptables -I INPUT -p tcp --dport 110 -j ACCEPT
/sbin/iptables -I INPUT -p tcp --dport 143 -j ACCEPT
/sbin/iptables -I INPUT -p tcp --dport 465 -j ACCEPT
/sbin/iptables -I INPUT -p tcp --dport 587 -j ACCEPT
/sbin/iptables -I INPUT -p tcp --dport 993 -j ACCEPT
/sbin/iptables -I INPUT -p tcp --dport 995 -j ACCEPT

centos7让防火墙设置生效:sudo firewall-cmd --reload   再次查看端口的开放情况:sudo firewall-cmd --list-all

 

centos6让防火墙设置生效:service iptables save    再次查看端口的开放情况:

 

关闭selinux,不关闭这个只能发送本地的账号,163,qq这类的外网邮箱是无法正常发送的哦!!!

临时关闭selinux : root#~: setenforce 0

查看selinux 状态 : getenforce

永久关闭selinux:vim /etc/sysconfig/selinux 将SELINUX=enforcing改为SELINUX=disabled

先卸载默认安装的
yum -y remove sendmail
yum -y remove postfix

安装:
yum -y install postfix
yum -y install dovecot
yum -y install crontabs  (这个是如果初始安装了postfix的话,卸载时会顺带把它卸载掉,所以要重新安装)
yum -y install cyrus-sasl* (如果这个已经安装了,这个千万不要卸载哦,卸载了重启服务器就崩溃了哦)

邮箱域名解析设置:

我这里使用的收发邮件域名为:mmoga.buruyouni.com

TXT记录SPF用于反垃圾,不设置的话大厂不收你的邮件哦,格式:v=spf1 a ipv4:185.242.104.20 -all 换成你自己的ip就行了

 

配置好域名解析接下来配置postfix

修改main.cf文件:vim /etc/postfix/main.cf

    75行   修改为:myhostname = mmoga.buruyouni.com  #这里我上面的域名解析配置成这样的,你自己改成你自己的

    83行   修改为:mydomain = mmoga.buruyouni.com #这里我上面的域名解析配置成这样的,你自己改成你自己的

    99行   修改为:myorigin = $mydomain

    116行 修改为:inet_interfaces = all

    119行 修改为:inet_protocols = ipv4

    164行 修改为:mydestination = $myhostname, localhost.$mydomain, localhost, $mydomain

    264行 修改为:mynetworks = 127.0.0.0/8

    419行 修改为:home_mailbox = Maildir/

    569行 加参数:smtpd_banner = $myhostname ESMTP

然后在文本末尾插入,或者就在这里插入下面的内容也行,随便你啦!

    message_size_limit = 10485760
    mailbox_size_limit = 1073741824
    cyrus_sasl_config_path =
    send_cyrus_sasl_authzid = no
    smtpd_sasl_auth_enable = yes
    smtpd_sasl_authenticated_header = no
    smtpd_sasl_exceptions_networks =
    smtpd_sasl_local_domain =
    smtpd_sasl_path = smtpd
    smtpd_sasl_security_options = noanonymous
    smtpd_sasl_tls_security_options = $smtpd_sasl_security_options
    smtpd_sasl_type = cyrus

=后面没有值是不是写错了?没错,=后面没写的就是没写,没有写错。

 

    修改dovecot.conf文件:vim /etc/dovecot/dovecot.conf

    24行   修改为:protocols = imap pop3 lmtp

    30行   修改为:listen = *


    修改10-auth.conf文件:vim  /etc/dovecot/conf.d/10-auth.conf

    9行   修改为:disable_plaintext_auth = no
    97行  修改为:auth_mechanisms = plain login


    修改10-mail.conf文件:vim /etc/dovecot/conf.d/10-mail.conf

    30行   修改为:mail_location = maildir:~/Maildir

    修改10-master.conf文件:vim /etc/dovecot/conf.d/10-master.conf

    88行-90行  修改为:

    unix_listener /var/spool/postfix/private/auth {
        mode = 0666
        user = postfix    
        group = postfix

    }

    修改10-ssl.conf文件:vim /etc/dovecot/conf.d/10-ssl.conf 这

    6行   修改为:ssl = no

    修改hostname:vim /etc/hosts  在文件末尾插入:185.242.104.20 mmoga.buruyouni.com
    立刻生效:hostname mmoga.buruyouni.com
    
    更改servename vim /etc/resolv.conf
        nameserver 114.114.114.114
        nameserver 8.8.8.8
    chmod 0755 /etc/resolv.conf   

4.重启服务:   

    service postfix restart&&service dovecot restart&&service saslauthd restart

    chkconfig postfix on    设置开机启动
    chkconfig dovecot on
    chkconfig saslauthd on

5.添加用户(也是邮箱用户)

    useradd admin&&passwd admin  --> YANGxing123

    useradd service&&passwd service  --> YANGxing123

6.创建邮件存储目录:
    su admin -c "mkdir /home/admin/Maildir"
    chown -R admin:admin /home/admin/Maildir 

    su service -c "mkdir /home/service/Maildir"
    chown -R service:service /home/service/Maildir

7.查看日志
    tail -f /var/log/maillog

查看邮件队列    postqueue -p
清除所有发送队列     postsuper -d ALL

 

然后用Outlook配置收发邮件就行了,现在可以给qq,163这些大厂发邮件了哦!!!

 

 

 

 

 

 

 

 

  • 1
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值