阿里云Centos7.3实践:搭建Sendmail服务器和配置
*以服务器地址120.79.254.2为例,服务器具体地址数值仅为示范所需,并非真实所用地址,如有冒犯,请联系更改。
1. 切换权限
sudo su root
2.安装DNS服务器软件包
yum install bind -y
yum install bind-libs -y
3.配置/etc/named.conf文件
vim /etc/named.conf
修改:
listen-on port 53 { any; };
allow-query { any; };增加:
zone "uc-knight.top" IN{
type master;
file "uc-knight.top.zone";
};
zone "254.79.120.in-addr.arpa" IN{
type master;
file "254.79.120.zone";
};
4.配置 /var/named/uc-knight.top.zone 文件
vim /var/named/uc-knight.top.zone
$ttl 600
@ IN SOA lance.uc-knight.top. lance.www.uc-knight.top.(2018060601 10800 3600 604800 38400 )
; Serial Refresh Retry Expire MinumumTTL
; Serial<2^32 Refresh>=Retry*2 Refresh+Retry<Expire
; Expire>=Retry*10
@ IN NS lance.uc-knight.top.
lance.uc-knight.top. IN A 120.79.254.2
@ IN MX 5 www.uc-knight.top.
www.uc-knight.top. IN A 120.79.254.2
5.配置 /var/named/254.79.120.zone 文件
vim /var/named/254.79.120.zone
$ttl 600
@ IN SOA lance.uc-knight.top. lance.www.uc-knight.top.(
2018060601 10800 3600 604800 38400 )
; Serial Refresh Retry Expire MinumumTTL
; Serial<2^32 Refresh>=Retry*2 Refresh+Retry<Expire
; Expire>=Retry*10
@ IN NS lance.uc-knight.top.
2 IN PTR lance.uc-knight.top.
6.启动named服务,并设为开机自启
systemctl start named
systemctl enable named
*7.DNS客户端配置(注意不是服务器端)
Linux: yum install bind-utils -y 然后编辑 vim /etc/resolv.conf
本例中为 nameserver 120.79.254.2
Windows: 本地连接/网络适配器-ipv4协议-手动配置输入dns地址
本例中为 使用下面的DNS服务器地址- 120.79.254.2
**额外小内容:web服务器配置(基于完成以上DNS配置步骤)
a.安装web服务器软件包
yum install httpd -y
yum install httpd-tools -y
yum install http-manual -y
b.修改/etc/httpd/conf/httpd.conf 文件
vim /etc/httpd/conf/httpd.conf
修改以下内容
ServerAdmin [email protected]
ServerName www.uc-knight.top
c.将网页保存到/var/www/html目录中
本例使用echo命令生成index.html文件
echo "Welcome to uc-knight.top! " >/var/www/html/index.html
d.启动httpd服务,设为开机自启
systemctl start httpd
systemctl enable httpd
8.安装Sendmail服务器软件包(sendmail, sendmail-cf, procmail, m4)
yum install sendmail -y
yum install sendmail-cf -y
9.验证邮件交换器设置(通过配置好DNS的客户端,即完成了执行第7点的客户端)
nslookup -q=mx uc-knight.top
输出为:
Server: 120.79.254.2
Address: 120.79.254.2#53
uc-knight.top mail exchanger = 5 www.uc-knight.top.
10.配置 /etc/mail/sendmail.mc 文件
vim /etc/mail/sendmail.mc
修改:
dnl # DAEMON_OPTIONS(`Port=smtp,Addr=127.0.0.1, Name=MTA')dnl
LOCAL_DOMAIN(`uc-knight.top')dnl
11.使用m4进行重定向/etc/mail/sendmail.cf
m4 /etc/mail/sendmail.mc >/etc/mail/sendmail.cf
12.vim /etc/mail/local-host-names
增加:
uc-knight.top <--域
www.uc-knight.top <--邮件主机名13.vim /etc/hosts
增加:
120.79.254.2 lance www.uc-knight.top
服务器ip地址;主机名;邮箱主机名
**.修改主机名(静态 瞬态 灵活主机名同时修改)
hostnamectl set-hostname <hostname>
**查询主机名 hostname -f
或 vim /etc/hostname
*14.vim /etc/mail/access
120.79.254 RELAY
uc-knight.top RELAY
修改后重定向:
makemap hash /etc/mail/access.db </etc/mail/access
*15.编辑/etc/aliases文件
编辑后使用newaliases生成/etc/aliases.db数据库
16.运行sendmail服务,设置开机自启
systemctl start sendmail
systemctl enable sendmail
*可使用 systemctl status sendmail 查看是否已启动
*可使用 systemctl status sendmail -l 查看服务具体启动情况
*可使用 systemctl is-enabled sendmail 查询是否已设置为开机启动
17.安装dovecot软件包
yum install dovecot -y
18.vim /etc/dovecot/dovecot.conf
修改:
protocols = imap pop3 lmtp
listen = *
base_dir = /var/run/dovecot/
19.运行dovecot服务,设为开机自启
systemctl start dovecot
systemctl enable dovecot
开始测试 在配置好dns的客户端上 远程登陆pop3端口110
*SMTP 端口 TCP 25
*POP3 端口 TCP 110
*IMAP 端口 TCP 143
telnet 120.79.254.2 110
user test
pass test
(用户自己在系统中添加)
问题一:输入user test 回车后出现
-ERR [AUTH] Plaintext authentication disallowed on non-secure (SSL/TLS) connections.
解决:
vim /etc/dovecot/conf.d/10-auth.conf
修改
disable_plaintext_auth = no
vim /etc/dovecot/conf.d/10-ssl.conf
修改
ssl = no
重启dovecot服务
systemctl restart dovecot
问题二:修改问题一后,输入pass test,出现
-ERR [SYS/TEMP] Internal error occurred. Refer to server log for more information.
Connection closed by foreign host.使用命令查看log
tail /var/log/maillog
Jun 6 23:43:29 iz6yiqbo5vklydz dovecot: pop3(test): Error: user test: Initialization failed: Namespace '': Mail storage autodetection failed with home=/home/test
Jun 6 23:43:29 iz6yiqbo5vklydz dovecot: pop3(test): Error: Invalid user settings. Refer to server log for more information.解决: vim /etc/dovecot/conf.d/10-mail.conf
设置mail_location参数
mail_location = mbox:~/mail:INBOX=/var/mail/%u
问题三:接着修改完问题二后,继续登录,出现
-ERR [SYS/PERM] Permission denied
Connection closed by foreign host.
查看日志 tail /var/log/maillog
Error: chown(/home/test/mail/.imap, group=12(mail)) failed: Operation not permitted (egid=1002(test), group based on /var/mail/test - see http://wiki2.dovecot.org/Errors/ChgrpNoPerm)
Jun 6 23:51:12 iz6yiqbo5vklydz dovecot: pop3(test): Error: Couldn't open INBOX: Permission denied
Jun 6 23:51:12 iz6yiqbo5vklydz dovecot: pop3(test): Couldn't open INBOX top=0/0, retr=0/0, del=0/0, size=0
解决方案
更改权限 chmod 0600 /var/mail/* (或者权限改为777等)
本例中为test用户 故命令为 chmod 0600 /var/mail/test
**使用命令查看日志文件
cat /var/log/maillog
tail /var/log/maillog
**不要用root用户远程登录邮箱服务器
WINDOWS客户端登录示例(需要先配置DNS)
1.FOXMAIL
或者 直接输入邮件服务器IP地址 则不需要配置DNS
2.THUNDERBIRD
参考自:http://linux.vbird.org/linux_server/0350dns.php (DNS相关知识和设置)
https://wenku.baidu.com/view/09ada240a32d7375a5178006.html (配置dovecot常见错误问题 问题一二解决方案)
https://wiki2.dovecot.org/Errors/ChgrpNoPerm?spm=5176.10173289.0.0.70742e77HdSTBU(问题三解决方案)