centos7.9搭建post邮件系统(非加密邮箱部署、云主机上面部署)

注意:如果是云主机提前开放2525 25 110 143端口
在这里插入图片描述

  1. 安装postfix
[root@10-9-146-206 ~]# yum install -y postfix
  1. 配置postfix
[root@10-9-146-206 ~]# tee /etc/postfix/main.cf <<EOF
queue_directory = /var/spool/postfix
command_directory = /usr/sbin
daemon_directory = /usr/libexec/postfix
data_directory = /var/lib/postfix
mail_owner = postfix
myhostname = mail.percent.com
mydomain = percent.com
myorigin = \$mydomain
inet_interfaces = all
inet_protocols = all
mydestination = \$myhostname, localhost.\$mydomain, localhost, \$mydomain
#注意这条配置,由于之前是注销的上面一条mydestination = \$myhostname, localhost.\$mydomain, localhost
#导致最后发送邮件时查看maillog报status=bounced (mail for jjonline.com.cn loops back to myself)
#邮件回退给了自己,没有发送出去
unknown_local_recipient_reject_code = 550
mynetworks = 0.0.0.0/0
#这个信任域网段根据自己需求配置,最简单的就是配置0.0.0.0/0 所有网段都可以发送
alias_maps = hash:/etc/aliases
alias_database = hash:/etc/aliases
home_mailbox = Maildir/
smtpd_banner = \$myhostname ESMTP \$mail_name (\$mail_version)
broken_sasl_auth_clients = yes
smtpd_client_restrictions = permit_sasl_authenticated
smtpd_recipient_restrictions = permit_mynetworks, permit_sasl_authenticated, reject_unauth_destination
smtpd_sasl_auth_enable = yes
smtpd_sasl_security_options = noanonymous
message_size_limit = 5242880
smtpd_relay_restrictions = permit_mynetworks,permit_sasl_authenticated,defer_unauth_destination
smtpd_sasl_type = dovecot
#增加了dovecot
smtpd_sasl_path = private/auth
debug_peer_level = 2
debugger_command = PATH=/bin:/usr/bin:/usr/local/bin:/usr/X11R6/bin ddd \$daemon_directory/\$process_name \$process_id & sleep 5
sendmail_path = /usr/sbin/sendmail.postfix
newaliases_path = /usr/bin/newaliases.postfix
mailq_path = /usr/bin/mailq.postfix
setgid_group = postdrop
html_directory = no
manpage_directory = /usr/share/man
sample_directory = /usr/share/doc/postfix-2.10.1/samples
readme_directory = /usr/share/doc/postfix-2.10.1/README_FILES
EOF
  1. 启动postfix
[root@10-9-146-206 ~]# systemctl start postfix
[root@10-9-146-206 ~]# systemctl enable postfix
  1. 安装cyrus-sasl
[root@10-9-146-206 ~]# yum -y install cyrus-sasl
  1. 配置sasl
[root@10-9-146-206 ~]# tee /etc/sysconfig/saslauthd <<EOF
SOCKETDIR=/run/saslauthd
MECH=shadow
FLAGS=
EOF
[root@10-9-146-206 ~]# tee /etc/sasl2/smtpd.conf <<EOF
pwcheck_method: saslauthd
mech_list:plain login CRAM-MD5 DIGEST-MD5
log_level: 3
saslauthd_path:/var/run/saslauthd/mux
EOF
  1. 启动sasl
[root@10-9-146-206 ~]# systemctl start saslauthd
[root@10-9-146-206 ~]# systemctl enable saslauthd
  1. 测试sasl
[root@10-9-146-206 ~]# useradd mail &&echo 'bfdmail'| passwd --stdin mail
Changing password for user mail.
passwd: all authentication tokens updated successfully.
[root@10-9-146-206 ~]#  su - mail
[mail@10-9-146-206 ~]$ mkdir -p ~/mail/.imap/INBOX
[mail@10-9-146-206 ~]$ testsaslauthd -u mail -p 'bfdmail'
0: OK "Success."
[mail@10-9-146-206 ~]$ exit
[root@10-9-146-206 ~]#  userdel -r mail
  1. 安装dovecot
[root@10-9-146-206 ~]# yum -y install dovecot dovecot-devel dovecot-mysql pam-devel
  1. 配置dovecot
[root@10-9-146-206 ~]# tee /etc/dovecot/dovecot.conf <<EOF
auth_mechanisms = plain login
mbox_write_locks = fcntl
passdb {
    driver = pam
}
service auth {
    unix_listener /var/spool/postfix/private/auth {
        group = postfix
        mode = 0660
        user = postfix
    }
    user = root
}
#ssl_cert = </etc/pki/dovecot/certs/dovecot.pem
#ssl_key = </ect/pki/dovecot/private/dovecot.pem
userdb {
    driver = passwd
}
ssl = no
mail_location = maildir:~/Maildir
disable_plaintext_auth = no
EOF
  1. 启动dovecot
[root@10-9-146-206 ~]# systemctl start dovecot
[root@10-9-146-206 ~]# systemctl enable dovecot
  1. 创建邮件用户
[root@10-9-146-206 ~]# useradd user1 && echo '123456'| passwd --stdin user1
Changing password for user user1.
passwd: all authentication tokens updated successfully.
[root@10-9-146-206 ~]# useradd user2 && echo '123456'| passwd --stdin user2
Changing password for user user2.
passwd: all authentication tokens updated successfully.
  1. 激活用户
[root@10-9-146-206 ~]# telnet 106.75.118.94 pop3
Trying 106.75.118.94...
Connected to 106.75.118.94.
Escape character is '^]'.
+OK Dovecot ready.
user user1
+OK
pass 123456
+OK Logged in.
quit
+OK Logging out.
Connection closed by foreign host.
[root@10-9-146-206 ~]# ls /home/user1/
.bash_logout   .bash_profile  .bashrc        Maildir/
[root@10-9-146-206 ~]# ls /home/user1/Maildir/
cur  dovecot.index.log  dovecot-uidlist  dovecot-uidvalidity  dovecot-uidvalidity.61c43406  new  tmp
[root@10-9-146-206 ~]# telnet 106.75.118.94 pop3
Trying 106.75.118.94...
Connected to 106.75.118.94.
Escape character is '^]'.
+OK Dovecot ready.
user user2
+OK
pass 123456
+OK Logged in.
quit
+OK Logging out.
Connection closed by foreign host.
[root@10-9-146-206 ~]# ls /home/user2/
.bash_logout   .bash_profile  .bashrc        Maildir/
[root@10-9-146-206 ~]# ls /home/user2/Maildir/
cur  dovecot.index.log  dovecot-uidlist  dovecot-uidvalidity  dovecot-uidvalidity.61c43406  new  tmp
  1. 配置本地hosts
[root@10-9-146-206 ~]# vim /etc/hosts
106.75.118.94 mail.percent.com
106.75.118.94 percent.com
#本地Windows也需要配置
#C:\Windows\System32\drivers\etc\hosts
  1. 修改post端口
    因为云主机不允许开发25端口 所以只能进行手动修改
有的时候SMTP的默认25端口不能用会导致无法使用邮箱功能,解决办法就是添加多端口。
vim /etc/postfix/master.cf
在已有第一行:
smtp      inet  n       -       n       -       -     smtpd
之后添加:
smtp2      inet  n       -       n       -       -     smtpd
#修改/etc/services文件,增加smtp2监听端口,本文以2525端口为例
vim /etc/services
找到:
smtp            25/tcp          mail
其后添加:
smtp2           2525/tcp        mail2
smtp2           2525/udp        mail2
#重启postfix
service postfix restart
  1. 配置邮箱

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

  1. 测试邮箱发送

在这里插入图片描述

  1. 查看两个邮箱是否接收成功

在这里插入图片描述

  • 5
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值