当前位置:   article > 正文

自主搭建邮件服务器_自建邮箱服务器

自建邮箱服务器

邮件服务器搭建

一、mail服务器初始化配置

1.修改主机名

[root@localhost /]# hostnamectl --static set-hostname mail.drock.top|bash

2.关闭防火墙和selinux

  1. [root@localhost /]# systemctl stop firewalld && systemctl disable firewalld
  2. [root@localhost /]# setenforce 0

3.同步时间

[root@localhost /]# yum -y install ntpdate && ntpdate ntp.aliyun.com

4.安装软件

[root@localhost /]# yum -y install postfix dovecot cyrus-sasl-* mailx

二、修改配置文件

1.配置postfix,备份cp /etc/postfix/main.cf /etc/postfix/main-old.cf

  1. [root@localhost /]# cat /etc/postfix/main.cf
  2. mail_owner = postfix
  3. myhostname = mail.liqing-test.top
  4. mydomain = liqing-test.top
  5. myorigin = $mydomain
  6. inet_interfaces = all
  7. inet_protocols = ipv4
  8. mydestination = $myhostname, localhost.$mydomain, localhost, $mydomain, mail.$mydomain, www.$mydomain, ftp.$mydomain
  9. local_recipient_maps
  10. mynetworks = 0.0.0.0/0
  11. relay_domains = $mydestination
  12. alias_maps = hash:/etc/aliases
  13. alias_database = hash:/etc/aliases
  14. smtpd_banner = $myhostname ESMTP
  15. # 在最下面新增
  16. smtpd_sasl_type = dovecot
  17. smtpd_sasl_path = private/auth
  18. smtpd_sasl_local_domain =
  19. smtpd_sasl_auth_enable = yes
  20. smtpd_sasl_security_options = noanonymous
  21. broken_sasl_auth_clients = yes
  22. smtpd_recipient_restrictions = permit_mynetworks,permit_auth_destination,permit_sasl_authenticated
  23. smtpd_client_restrictions = permit_sasl_authenticated

2.配置dovectot

 2.1配置监听协议:

  1. [root@localhost /]# cat /etc/dovecot/dovecot.conf
  2. protocols = imap pop3 lmtp
  3. listen = *
  4. login_trusted_networks = 0.0.0.0/0
  5. dict {
  6. }
  7. !include conf.d/*.conf
  8. !include_try local.conf

2.2配置登录方式

  1. [root@localhost /]# cat /etc/dovecot/conf.d/10-auth.conf
  2. disable_plaintext_auth = no
  3. auth_mechanisms = plain login
  4. !include auth-system.conf.ext

2.3配置邮件存储位置

  1. [root@localhost /]# cat /etc/dovecot/conf.d/10-mail.conf
  2. mail_location = mbox:~/mail:INBOX=/var/mail/%u
  3. namespace inbox {
  4. inbox = yes
  5. }
  6. first_valid_uid = 1000
  7. mbox_write_locks = fcntl
  1. [root@localhost /]# cat /etc/dovecot/conf.d/10-master.conf
  2. service auth {
  3.    unix_listener /var/spool/postfix/private/auth {
  4.    mode = 0666
  5.    user = postfix
  6.    group = postfix
  7.    }
  8. }

2.4配置ssl(关闭)

  1. [root@localhost /]# cat /etc/dovecot/conf.d/10-ssl.conf
  2. ssl = no

3.配置sasl2

3.1配置系统认证

  1. [root@localhost /]# cat /etc/sysconfig/saslauthd
  2. SOCKETDIR=/run/saslauthd
  3. MECH=shadow
  4. FLAGS=

3.2配置登录方式

  1. [root@localhost /]# cat /etc/sasl2/smtpd.conf
  2. pwcheck_method: saslauthd
  3. mech_list: PLAIN LOGIN
  4. log_level:3

4.启动服务

  1. [root@localhost /]# systemctl restart dovecot
  2. [root@localhost /]# systemctl restart postfix
  3. [root@localhost /]# systemctl restart saslauthd
  4. [root@localhost /]# systemctl enable dovecot
  5. [root@localhost /]# systemctl enable postfix
  6. [root@localhost /]# systemctl enable saslauthd

5.创建用户并设置pass

  1. [root@localhost /]# useradd -m drock && echo 123456 | passwd --stdin drock
  2. [root@localhost /]# su - drock
  3. [drock@mail ~]$ mkdir -p ~/mail/.imap/INBOX
  4. [drock@mail ~]$ chmod -R 750 ~/mail        #(这不操作不做会在使用foxmail登录时报错{Error: Couldn't open INBOX: Permission denied})
  5. [drock@mail ~]$ exit

6.配置mailx

  1. [root@localhost /]# vi /etc/mail.rc
  2. set from=drock@drock.top
  3. set smtp=mail.drock.top
  4. set smtp-auth-user=drock
  5. set smtp-auth-password=123456
  6. set smtp-auth=login

四、发送邮件测试

1.命令行发送邮件测试

[root@localhost /]# echo "邮件服务器测试" | mail -s "邮件服务器测试" other-email@163.com

2.使用foxmail登录并发送邮件测试

五、报错

1.权限被拒绝

在使用foxmail登录邮箱时提示权限被拒绝,这是因为在邮箱用户的家目录下mail文件权限不是750,设置为750后解决。

[drock@mail ~]$ chmod -R 750 ~/mail

2.无法找到主机

邮件在发送时会根据邮件地址的解析记录去查找mx记录,这里我在向腾讯的企业邮箱发送测试邮件时找不到腾讯的邮箱地址。我在内网的dns代理中加入了腾讯的mx记录后解决

  1. [root@dns- ~]# grep qq /etc/dnsmasq.conf
  2. mx-host=***.com,mxbiz2.qq.com,10
  3. mx-host=***.com,mxbiz1.qq.com,5

3.邮件被拒绝

在我向腾讯企业邮箱发送测试邮件时日志里出现了550邮件连接被拒绝的情况,此情况在邮件中设置白名单后解决。

声明:本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:【wpsshop博客】
推荐阅读
相关标签
  

闽ICP备14008679号