脚本宝典收集整理的这篇文章主要介绍了在centos环境中简单搭建邮件服务器,脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。
邮件收、发服务器是分开的,也就是我们需要搭建一个邮件发送服务器(Postfix)和一个邮件收取服务器(Dovecot)。 本文会搭建收、发两个服务器,并用邮件客户端(Foxmail,outlook)做测试。
Centos ip 192.168.31.208/24
win10ip 192.168.31.157/24
vim /etc/hostname # 如: mail.saltfish.com
hostnamectl set-hostname mail.saltfish.com
[root@mail ~]# iptables -F [root@mail ~]# iptables-save
[root@mail ~]#systemctl stop firewalld [root@mail ~]#systemctl disable firewalld
具体观看:Centos中配置一个简单的dns服务器_不咸还不鱼的博客-CSDN博客
$TTL 1D | #生存周期为1天 | ||||
@ | IN SOA | saltfish.com. | root.saltfish.com. | ( | |
#授权信息开始: | #DNS区域的地址 | #域名管理员的邮箱(不要用@符号) | |||
0;serial | |||||
1D;refresh | |||||
1H;retry | |||||
1W;expire | |||||
3H );minimum | |||||
NS | ns.saltfish.com. | #域名服务器记录 | |||
ns | IN A | 192.168.31.208 | #地址记录(ns.saltfish.com.) | ||
@ | IN MX 10 | mail.saltfish.com. | |||
IN A | 192.168.31.208 | #地址记录(mail.saltfish.com.) |
当然Cetnos也要指向自己
Postfix Postfix 是实现 SMTP 协议的软件,也叫做邮件发送服务器。
上面说的邮件客户端将邮件扔给它,由它对邮件进行转发,至于怎么转发,SMTP 协议制定了规则,而 Postfix 负责具体事情,我们只需要修改 Postfix 配置文件要求它按照我们的想法去做。
yum -y install postfix
第1步:在第76行定义一个名为myhostname的变量,用来保存服务器的主机名称 [root@mail ~]# vim /etc/postfix/main.cf
68 # INTERNET HOST AND DOMAIN NAMES 69 # 70 # The myhostname parameter specifies the internet hostname of this 71 # mail system. The default is to use the fully-qualified domain name 72 # from gethostname(). $myhostname is used as a default value for many 73 # other configuration parameters. 74 # 75 #myhostname = host.domain.tld 76 myhostname = mail.saltfish.com 77
第2步:在第83行定义一个名为mydomain的变量,用来保存邮件域的名称
78 # The mydomain parameter specifies the local internet domain name. 79 # The default is to use $myhostname minus the first component. 80 # $mydomain is used as a default value for many other configuration 81 # parameters. 82 # 83 mydomain = saltfish.com 84
第3步:在第99行调用前面的mydomain变量,用来定义发出邮件的域
93 # 94 # For the sake of consistency between sender and recipient addresses, 95 # myorigin also specifies the default domain name that is appended 96 # to recipient addresses that have no @domain part. 97 # 98 #myorigin = $myhostname 99 myorigin = $mydomain 100
第4步:在第116行定义网卡监听地址。可以指定要使用服务器的哪些IP地址对外提供电子邮件服务;也可以干脆写成all,表示所有IP地址都能提供电子邮件服务:
111 # Note: you need to stop/start Postfix when this parameter changes. 112 # 113 #inet_interfaces = all 114 #inet_interfaces = $myhostname 115 #inet_interfaces = $myhostname, localhost 116 inet_interfaces = all 117
第5步:在第164行定义可接收邮件的主机名或域名列表
161 # 162 # See also below, section "REJECTING MAIL FOR UNKNOWN LOCAL USERS". 163 # 164 mydestination = $myhostname,$mydomain 165 #mydestination = $myhostname, localhost.$mydomain, localhost, $mydomain 166 #mydestination = $myhostname, localhost.$mydomain, localhost, $mydomain, 167 # mail.$mydomain, www.$mydomain, ftp.$mydomain 168
创建电子邮件系统的登录账户: [root@mail ~]# useradd admin [root@mail ~]# echo "admin" | passwd --stdin admin Changing password for user liuchuan. passwd: all authentication tokens updated successfully. [root@mail ~]# systemctl restart postfix [root@mail ~]# systemctl enable postfix Created symlink /etc/systemd/system/multi-user.target.wants/postfix.service → /usr/lib/systemd/system/postfix.service.
Dovecot 实现了 POP 和 IMOP 协议,也叫做邮件收取服务器。如果只搭建了 Postfix 而没有它,不好意思,你是收不到邮件的。
yum -y install dovecot
2.配置Dovecot
[root@mail ~]# vim /etc/dovecot/dovecot.conf ……… 22 23 # Protocols we want to be serving. 24 protocols = imap pop3 lmtp 25 disable_plaintext_auth = no 26 ………… 在主配置文件的第49行,设置允许登录的网段地址 47 # for authentication checks). disable_plaintext_auth is also ignored for 48 # these networks. Typically you'd specify your IMAP proxy servers here. 49 login_trusted_networks = 192.168.31.0/24 50
配置邮件格式与存储路径,只需要将配置文件中第25行前面的井号(#)删除即可。 [root@linuxprobe ~]# vim /etc/dovecot/conf.d/10-mail.conf 22 # See doc/wiki/Variables.txt for full list. Some examples: 23 # 24 # mail_location = maildir:~/Maildir 25 mail_location = mbox:~/mail:INBOX=/var/mail/%u 26 # mail_location = mbox:/var/mail/%d/%1n/%n:INDEX=/var/indexes/%d/%1n/%n 27 #
然后切换到配置Postfix服务程序时创建的boss账户,并在家目录中建立用于保存邮件的目录。记得要重启Dovecot服务并将其添加到开机启动项中 [root@mail ~]# su - admin [admin@mail ~]$ mkdir -p mail/.imap/INBOX [admin@mail ~]$ exit logout [root@mail ~]# systemctl restart dovecot [root@mail ~]# systemctl enable dovecot Created symlink /etc/systemd/system/multi-user.target.wants/dovecot.service → /usr/lib/systemd/system/dovecot.service.
1.选择其他邮箱
2.手动配置
3.模式选择pop3,点击创建
就成功了
给自己发一封测试邮件
获取成功
电子邮件地址:服务器用户@域名
密码:服务器用户密码
报错没关系,下一页
成功
收到测试信
以上是脚本宝典为你收集整理的在centos环境中简单搭建邮件服务器全部内容,希望文章能够帮你解决在centos环境中简单搭建邮件服务器所遇到的问题。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。