linux centos7 完整邮件服务器搭建及调用_2018_lcf
我的系统是centos7.5(7以上的应该都适用)
—1—设置域名
域名或自建DNS照下面方式设置即可
—2—安装软件,配置基本收发信功能
-A- 安装软件
[[email protected] ~]# yum -y remove postfix.x86_64 dovecot.x86_64 cyrus-sasl
[[email protected] ~]# postconf –a //验证是否支持cyrus dovecot功能
cyrus
dovecot
(postfix主要是为发件服务25,devocot为收件服务110、145, cyrus-sasl登陆验证服务)
-B-修改postfix主配置文件,启动服务
[[email protected] ~]# vim /etc/postfix/main.cf
#修改以下配置
myhostname = mail.ald8.cn //邮件服务器的主机名
mydomain = ald8.cn //邮件域
myorigin = $mydomain //往外发邮件的邮件域
inet_interfaces = all //监听的网卡
inet_protocols = all
mydestination = $myhostname, $mydomain //服务的对象
home_mailbox = Maildir/ //邮件存放的目录
#新添加以下配置
#--------自定义(下面可以复制粘贴到文件最后面,用于设置服务器验为主,第一行设置发送附件大小)
#message_size_limit = 100000
smtpd_sasl_auth_enable = yes
smtpd_sasl_security_options = noanonymous
mynetworks = 127.0.0.0/8
smtpd_recipient_restrictions = permit_mynetworks,permit_sasl_authenticated,reject_unauth_destination
[[email protected] ~]# postfix check //修改保存后检查配置文件是否有错
[[email protected] ~]# systemctl restart postfix.service
[[email protected] ~]# systemctl enable postfix.service
--配置补充说明--
- smtpd_sasl_auth_enable = yes //开启认证
- smtpd_sasl_security_options = noanonymous //不允许匿名发信
- mynetworks = 127.0.0.0/8 //允许的网段,如果增加本机所在网段就会出现允许不验证也能向外域发信
- smtpd_recipient_restrictions = permit_mynetworks,permit_sasl_authenticated,reject_unauth_destination
- //允许本地域以及认证成功的发信,拒绝认证失败的发信
-C-修改dovecot主配置文件,启动服务
[[email protected] ~]# vim /etc/dovecot/dovecot.conf
#修改以下配置
protocols = imap pop3 lmtp
listen = *, ::
!include conf.d/10-auth.conf
#新添加以下配置
#-----------自定义------------
ssl = no
disable_plaintext_auth = no
mail_location = maildir:~/Maildir
[[email protected] ~]# systemctl restart dovecot.service
[[email protected] ~]# systemctl enable dovecot.service
-D-修改 cyrus-sasl主配置文件
[[email protected] ~]# vim /etc/sasl2/smtpd.conf //这个是空文件,直接添加下面配置(配置认证方式)
pwcheck_method: saslauthd
mech_list: plain login
log_level:3
[[email protected] ~]# vim /etc/sysconfig/saslauthd //修改下面配置项(本地用户认证)
MECH=shadow
[[email protected] ~]# systemctl restart saslauthd.service
[[email protected] ~]# systemctl enable saslauthd.service
—3— 创建用户,安装telnet进行邮件收发测试
[[email protected] ~]# yum -y install telnet-server.x86_64 telnet.x86_64
[[email protected] ~]# useradd lcf -s /sbin/nologin
[[email protected] ~]# useradd zjc -s /sbin/nologin
[[email protected] ~]# echo '123123' | passwd --stdin lcf
[[email protected] ~]# echo '123123' | passwd --stdin zjc
-A-发送本地邮件测试
--------------连接服务器的25端口进行简单发信测试-----------
[[email protected] ~]# telnet mail.ald8.cn 25
//连接成功,开始写信
helo mail.ald8.cn //声明本机的主机
mail from:[email protected] //声明发件人地址
rcpt to:[email protected] //声明收件人地址
data //写正文
HI THis is zjc, Good day!
. //记住这里是以点作为正文结束标记
quit // 退出
如图所示:
到这里信件就已经发送了,接下来是验证了。
-B-收取邮件验证
---------------收信验证---------------
[[email protected] ~]# telnet mail.aa.com 110
user lcf //收件人登录
pass 123 //邮箱密码
list //列表查看邮件
retr 1 //读取编号为1的邮件
quit //退出邮箱
如图所示:
查看到了发送的内容,那这里就算是收件成功了
-A-发送邮件到其它邮箱服务器
这里用mailx这个软件来测试发送
[[email protected] ~]# su - zjc
Last login: Sat Oct 20 16:20:01 CST 2018 from 193.112.217.131 on pts/2
[[email protected] ~]$ echo '这是测试' | mail -s '你好,164' [email protected]
再登陆到163邮箱查看是否收到邮件
妥妥的收到了邮件
到里邮箱的收发功能就都具备了。
—4— 调用邮箱(也就是调用这个服务器的smtp.pop3)
我这里用windows的163邮件代理接收发送客户端作演示
下载地址:http://mail.163.com/dashi/index.html (支持多个不同账户的邮箱接收和发送邮件,支持建用户组群发)
下载安装后,用linux创建好的用户名和密码和为登陆和服务器设置
我这是登陆设置好的了,收信和发信账号及密码就是在linux系统那里创建的账号和对应的密码。
设置验证成功后就可以畅发邮件了,记得别乱发垃圾邮件哦!
----如果有不明白的,可以留言我会解答。(转载请注明原地址,谢谢!)