Linux Centos7搭建邮件服务器
基于sendmail和Dovecot
一.关闭防火墙和selinux
systemctl stop firewalld
setenctoce 0
二.下载sendmail软件和其他的工具
禁用系统自带的postfix:alternatives --config mta :2
三.启用sendmail禁用postfix
[root@localhost named]# systemctl start sendmail
[root@localhost named]# systemctl enable sendmail
[root@localhost named]# systemctl mask postfix
Created symlink from /etc/systemd/system/postfix.service to /dev/null.
[root@localhost named]#
四.安装dovecot并启动
yum install -y dovecot
systemctl start dovecot
systemctl enable dovecot
五.修改配置文件内容
vim /etc/mail/sendmail.mc
将Addr修改成自己服务器的IP地址
修改成自己的域名
m4 /etc/mail/sendmail.mc > /etc/mail/sendmail.cf
将文件内容进行关联输出
六.修改mail转发配置
①修改access文件设置邮件中继:vi /etc/mail/access
添加自己的域名和网段地址
②makemap -r hash /etc/mail/access.db < /etc/mail/access
将文件修改内容输出到数据库
七.修改/etc/mail/local-host-names文件
重启邮件服务器:systemctl restart sendmail
vim /etc/mail/local-host-names
[root@localhost named]# systemctl restart sendmail
[root@localhost named]# groupadd test
[root@localhost named]# useradd stu -g test -s /sbin/nologin
[root@localhost named]# useradd teacher -g test -s /sbin/nologin
[root@localhost named]# passwd stu
更改用户 stu 的密码 。
新的 密码:
无效的密码: 密码少于 8 个字符
重新输入新的 密码:
passwd:所有的身份验证令牌已经成功更新。
[root@localhost named]# passwd teacher
更改用户 teacher 的密码 。
新的 密码:
无效的密码: 密码少于 8 个字符
重新输入新的 密码:
passwd:所有的身份验证令牌已经成功更新。
[root@localhost named]#
修改/etc/hosts文件
vi /etc/hosts
设置群发别名
vi /etc/aliases
执行
newaliases
八.测试发送邮件
telnet 192.168.100.20 25
#键入如下内容:
helo mail.dhy.com
#设置邮件主题是test email,发件人是root@dhy.com
mail from:"test email"root@dhy.com
# 设置收件人地址是stu@dhy.com
rcpt to:stu@dhy.com
# data表示开始写邮件的内容。
data
# 邮件内容的正文。
This is a test mail.
# 这里的点号表示邮件正文结束。
.
# 检查所传送的电子邮件是否送出或滞留在邮件服务器中。
mailq
九.配置dovecot
修改主配置文件/etc/dovecot/dovecot.conf:
vi /etc/dovecot/dovecot.conf
# Protocols we want to be serving.
protocols = imap pop3 lmtp
# A comma separated list of IPs or hosts where to listen in for connections.
# "*" listens in all IPv4 interfaces, "::" listens in all IPv6 interfaces.
# If you want to specify non-default ports or anything more complex,
# edit conf.d/master.conf.
listen = 192.168.100.130, ::
# Base directory where to store runtime data.
base_dir = /var/run/dovecot/
# Name of this instance. In multi-instance setup doveadm and other commands
# can use -i <instance_name> to select which instance is used (an alternative
# to -c <config_path>). The instance name is also added to Dovecot processes
# in ps output.
#instance_name = dovecot
# Greeting message for clients.
#login_greeting = Dovecot ready.
# Space separated list of trusted network ranges. Connections from these
# IPs are allowed to override their IP addresses and ports (for logging and
# for authentication checks). disable_plaintext_auth is also ignored for
# these networks. Typically you'd specify your IMAP proxy servers here.
login_trusted_networks = 192.18.100.0/24
十.配置邮件的格式与存储路径
vi /etc/dovecot/conf.d/10-mail.conf
修改文件夹权限
chmod 0600 /var/mail/*
重启dovecot服务:systemctl restart devocecot
十一.使用foxmail客户端进行测试
选择其他邮箱
选择手动设置
注意不要勾选那两个选框,端口是110和25如果是其他端口,需要手动开启防火墙相应的端口
POP服务器和SMTP服务器是自己的邮箱服务器IP地址
邮箱账号是刚才添加的用户和自己的域