自主搭建邮件服务器
郵件服務器搭建
一、mail服務器初始化配置
1.修改主機名
[root@localhost /]# hostnamectl --static set-hostname mail.drock.top|bash2.關閉防火墻和selinux
[root@localhost /]# systemctl stop firewalld && systemctl disable firewalld [root@localhost /]# setenforce 03.同步時間
[root@localhost /]# yum -y install ntpdate && ntpdate ntp.aliyun.com4.安裝軟件
[root@localhost /]# yum -y install postfix dovecot cyrus-sasl-* mailx二、修改配置文件
1.配置postfix,備份cp /etc/postfix/main.cf /etc/postfix/main-old.cf
[root@localhost /]# cat /etc/postfix/main.cfmail_owner = postfixmyhostname = mail.liqing-test.topmydomain = liqing-test.topmyorigin = $mydomaininet_interfaces = allinet_protocols = ipv4mydestination = $myhostname, localhost.$mydomain, localhost, $mydomain, mail.$mydomain, www.$mydomain, ftp.$mydomainlocal_recipient_maps mynetworks = 0.0.0.0/0relay_domains = $mydestinationalias_maps = hash:/etc/aliasesalias_database = hash:/etc/aliasessmtpd_banner = $myhostname ESMTP# 在最下面新增smtpd_sasl_type = dovecotsmtpd_sasl_path = private/authsmtpd_sasl_local_domain =smtpd_sasl_auth_enable = yessmtpd_sasl_security_options = noanonymousbroken_sasl_auth_clients = yessmtpd_recipient_restrictions = permit_mynetworks,permit_auth_destination,permit_sasl_authenticatedsmtpd_client_restrictions = permit_sasl_authenticated2.配置dovectot
?2.1配置監聽協議:
[root@localhost /]# cat /etc/dovecot/dovecot.confprotocols = imap pop3 lmtplisten = *login_trusted_networks = 0.0.0.0/0dict {}!include conf.d/*.conf!include_try local.conf2.2配置登錄方式
[root@localhost /]# cat /etc/dovecot/conf.d/10-auth.confdisable_plaintext_auth = noauth_mechanisms = plain login!include auth-system.conf.ext2.3配置郵件存儲位置
[root@localhost /]# cat /etc/dovecot/conf.d/10-mail.confmail_location = mbox:~/mail:INBOX=/var/mail/%unamespace inbox {inbox = yes}first_valid_uid = 1000mbox_write_locks = fcntl [root@localhost /]# cat /etc/dovecot/conf.d/10-master.confservice auth {unix_listener /var/spool/postfix/private/auth {mode = 0666user = postfixgroup = postfix}}2.4配置ssl(關閉)
[root@localhost /]# cat /etc/dovecot/conf.d/10-ssl.confssl = no3.配置sasl2
3.1配置系統認證
[root@localhost /]# cat /etc/sysconfig/saslauthdSOCKETDIR=/run/saslauthdMECH=shadowFLAGS=3.2配置登錄方式
[root@localhost /]# cat /etc/sasl2/smtpd.confpwcheck_method: saslauthdmech_list: PLAIN LOGINlog_level:34.啟動服務
[root@localhost /]# systemctl?restart?dovecot[root@localhost /]# systemctl?restart?postfix[root@localhost /]# systemctl restart?saslauthd[root@localhost /]# systemctl?enable dovecot[root@localhost /]# systemctl?enable postfix[root@localhost /]# systemctl enable saslauthd5.創建用戶并設置pass
[root@localhost /]# useradd -m drock && echo 123456 | passwd --stdin drock[root@localhost /]# su - drock[drock@mail ~]$ mkdir -p ~/mail/.imap/INBOX[drock@mail ~]$ chmod -R 750 ~/mail??????? #(這不操作不做會在使用foxmail登錄時報錯{Error: Couldn't open INBOX: Permission denied})[drock@mail ~]$ exit6.配置mailx
[root@localhost /]# vi?/etc/mail.rcset from=drock@drock.topset smtp=mail.drock.topset smtp-auth-user=drockset smtp-auth-password=123456set smtp-auth=login四、發送郵件測試
1.命令行發送郵件測試
[root@localhost /]# echo?"郵件服務器測試"?| mail?-s?"郵件服務器測試" other-email@163.com2.使用foxmail登錄并發送郵件測試
五、報錯
1.權限被拒絕
在使用foxmail登錄郵箱時提示權限被拒絕,這是因為在郵箱用戶的家目錄下mail文件權限不是750,設置為750后解決。
[drock@mail ~]$ chmod -R 750 ~/mail2.無法找到主機
郵件在發送時會根據郵件地址的解析記錄去查找mx記錄,這里我在向騰訊的企業郵箱發送測試郵件時找不到騰訊的郵箱地址。我在內網的dns代理中加入了騰訊的mx記錄后解決
[root@dns- ~]# grep qq /etc/dnsmasq.confmx-host=***.com,mxbiz2.qq.com,10mx-host=***.com,mxbiz1.qq.com,53.郵件被拒絕
在我向騰訊企業郵箱發送測試郵件時日志里出現了550郵件連接被拒絕的情況,此情況在郵件中設置白名單后解決。
總結
- 上一篇: vue 局部回到顶部_vue中回到顶部
- 下一篇: vijos1214——伤心的AsukaN