GVKun编程网logo

centos配置postfix邮件服务(centos部署邮件服务器)

11

最近很多小伙伴都在问centos配置postfix邮件服务和centos部署邮件服务器这两个问题,那么本篇文章就来给大家详细解答一下,同时本文还将给你拓展centos7postfix配置163邮箱发送

最近很多小伙伴都在问centos配置postfix邮件服务centos部署邮件服务器这两个问题,那么本篇文章就来给大家详细解答一下,同时本文还将给你拓展centos 7 postfix配置163邮箱发送邮件、Centos 7 安装 Postfix 用于发送提醒邮件、Centos 7.1搭建postfix 邮件系统、CentOS 7.2 部署邮件服务器(Postfix)等相关知识,下面开始了哦!

本文目录一览:

centos配置postfix邮件服务(centos部署邮件服务器)

centos配置postfix邮件服务(centos部署邮件服务器)

1.环境初始化

[[email protected] ~]# rpm -q centos-release //查看系统版本
centos-release-7-5.1804.el7.centos.x86_64

[[email protected] ~]# vi /etc/hostname //将主机名更改为邮件服务器域名mail.test.com

[[email protected] ~]# systemctl disable firewalld //禁止防火墙开机自启动

[[email protected] ~]# vi /etc/sysconfig/selinux //将未注释的SELINUX行的值改为disabled

[[email protected] ~]# vi /etc/fstab //编辑fstab配置文件,在最后一行添加如下:

/dev/cdrom /mnt iso9660 ro 0 0 //将vmware连接的光盘镜像开机自动以只读挂载到/mnt目录下

[[email protected] ~]# vi /etc/yum.repos.d/CentOS-Base.repo //编辑yum的配置文件,方便后续安装,配置内容如下,其他删除或注释:

[base]
name=CentOS-$releasever - Base
baseurl=file:///mnt
enabled=1
gpgcheck=0
////////////没看懂什么意思,为什么要这样做
[[email protected] ~]# reboot //重启让优化环境生效

2.搭建DNS环境域名解析,用于解析postfix地址

[[email protected] ~]# yum install -y bind //安装DNS服务器

[[email protected] ~]# vi /etc/named.conf //修改DNS主配置文件

listen-on port 53 { 192.168.49.129; };

allow-query { any; }; //修改这两行的内容

[[email protected] ~]# vi /etc/named.rfc1912.zones //修改子配置文件

zone “test.com” IN {

type master;

    file "test.com.zone";

};

zone “49.168.192.in-addr.arpa” {

type master;

    file "test.com.local";

}; //在最后添加一个正向和一个反向解析区域

[[email protected] ~]# cd /var/named/ //进入DNS服务器区域配置文件目录

[[email protected] named]# cp -p named.localhost test.com.zone

[[email protected] named]# cp -p named.localhost test.com.local //复制模板区域配置文件为指定区域配置文件。保留源文件权限,确定属组为named

[[email protected] named]# vi test.com.zone //编辑正向区域配置文件
$TTL 1D
@ IN SOA @ rname.invalid. (

0       ; serial
                                    1D      ; refresh
                                    1H      ; retry
                                    1W      ; expire
                                    3H )    ; minimum
    NS      @
    A       192.168.49.129
    mail      A       192.168.49.129
    MX 10   mail.test.com.

[[email protected] named]# vi test.com.local //编辑反向区域配置文件
$TTL 1D
@ IN SOA test.com. rname.invalid. (

0       ; serial
                                    1D      ; refresh
                                    1H      ; retry
                                    1W      ; expire
                                    3H )    ; minimum
    NS      mail.test.com.
    A       192.168.49.129
    MX 10   mail.test.com.
    129     PTR     mail.test.com.

[[email protected] named]# systemctl start named //启动DNS域名解析服务器

[[email protected] named]# yum install -y bind-utils //安装nslookup命令测试dns能否解析成功

[[email protected] named]# vi /etc/resolv.conf //给本机的DNS指向自己的DNS服务器

nameserver 192.168.49.129

[[email protected] named]# nslookup mail.test.com //解析服务器地址 //正向解析
Server: 192.168.49.129
Address: 192.168.49.129#53

Name: mail.test.com
Address: 192.168.49.129

//反向解析
[[email protected] named]# nslookup 192.168.49.129
Server: 192.168.49.129
Address: 192.168.49.129#53

129.49.168.192.in-addr.arpa name = mail.test.com.
//成功

3.安装postfix服务器并进行配置

一般是默认自动安装postfix服务器的。

[[email protected] named]# rpm -q postfix //检查系统是否已经安装了postfix服务器

postfix-2.10.1-6.el7.x86_64

[[email protected] named]# postconf -a //检查postfix是否支持cyrus dovecot功能,如果不支持需重新安装更新的版本

[[email protected] named]# vi /etc/postfix/main.cf //编辑postfix的配置文件,查找并修改对应配置项

myhostname = mail.test.com //本机主机名

mydomain = test.com //服务器域名

myorigin = $mydomain //初始域名

inet_interfaces = 192.168.80.181,127.0.0.1 //监听接口

inet_protocols = ipv4 //监听网络版本,可以不改

mydestination = myhostname,

mydomain //目标域

home_mailBox = Maildir/ //邮件目录,在用户家目录下

[[email protected] named]# postfix check //检查配置文件是否有语法错误

[[email protected] named]# systemctl start postfix //启动postfix服务器

//postconf -n该命令可查看postfix非默认配置
  • 1

4.邮件服务器简单发信测试

[[email protected] named]# groupadd mailusers //添加邮件账号组

[[email protected] named]# useradd -g mailusers -s /sbin/nologin jack //用户jack不允许登录(通过mailusers可以连接)

[[email protected] named]# passwd jack

[[email protected] named]# useradd -g mailusers -s /sbin/nologin tom

[[email protected] named]# passwd tom //添加jack、tom邮件服务测试账号

[[email protected] named]# yum install -y telnet //安装远程登录插件,用于登录25端口测试

[[email protected] named]# telnet mail.test.com 25 //远程登录25端口,如报错连接不上,重启postfix

如图表示正确


输入如下命令测试:

这里写图片描述

[[email protected] named]# ls /home/tom/Maildir/new/ //查看tom接收的邮件目录下的邮件

这里写图片描述


这个只能超级管理员查看邮件

centos 7 postfix配置163邮箱发送邮件

centos 7 postfix配置163邮箱发送邮件

[[email protected] .certs]# vim /etc/mail.rc #修改配置文件,最后面添加即可 set [email protected] set smtp.163.com set smtp-auth-user=wcczcl set smtp-auth-password=1454545 set smtp-auth=login set smtp-use-starttls set ssl-verify=ignore set nss-config-dir=/etc/pki/nssdb/

from:对方收到邮件时显示的发件人
smtp:指定第三方发邮件的smtp服务器地址
set smtp-auth-user:第三方发邮件的用户名
set smtp-auth-password:用户名对应的密码,有些邮箱填的是授权码
smtp-auth:SMTP的认证方式,默认是login,也可以改成CRAM-MD5或PLAIN方式

因为需要 163邮箱的 SSL 证书,所以我们还需要手动的获取163邮箱的证书保存到本地指定的目录里以备调用和验证,具体命令如下:

mkdir -p /root/.certs/
echo -n | openssl s_client -connect smtp.163.com:465 | sed -ne ‘/-BEGIN CERTIFICATE-/,/-END CERTIFICATE-/p‘ > ~/.certs/163.crt
certutil -A -n "GeoTrust SSL CA" -t "C," -d ~/.certs -i ~/.certs/163.crt
certutil -A -n "GeoTrust Global CA" -t "C," -d ~/.certs -i ~/.certs/163.crt
certutil -L -d /root/.certs

为了防止出现前文所说的发送邮件警告提示,还需要进入邮箱 SSL 证书存放目录 /root/.certs 里执行如下命令:

cd /root/.certs/
certutil -A -n "GeoTrust SSL CA - G3" -t "Pu,Pu,Pu" -d ./ -i 163.crt

返回如下提示即可:
Notice: Trust flag u is set automatically if the private key is present.

systemctl start postfix #启动邮件服务

测试:
echo "test" | mail -s "ec" [email protected]

Centos 7 安装 Postfix 用于发送提醒邮件

Centos 7 安装 Postfix 用于发送提醒邮件

1. 卸载 sendmail,没有安装 sendmail 的跳过

yum remove sendmail

2. 安装 Postfix

yum install postfix

 

3. 更改默认 MTA 为 Postfix

/usr/sbin/alternatives --set mta /usr/sbin/sendmail.postfix

4. 检查是否将 MTA 改为 Postfix

alternatives --display mta

5. 配置 Postfix,修改 main.cf

vi /etc/postfix/main.cf

查找以下各项,去掉最前面的 #,参考说明修改

myhostname = www.ifshow.com
mydomain = ifshow.com
myorigin = $mydomain
inet_interfaces = all
mydestination = $myhostname, localhost.$mydomain, localhost, $mydomain
relay_domains =
home_mailbox = Maildir/

myhostname 是服务器的主机名,mydomain 是域名,myorigin 定义邮箱后缀,inet_interfaces 是指定使用的网络接口,relay_domains 是转发域留空,home_mailbox 是指定邮箱格式。

6. 启动 Postfix 并设为开机自启

systemctl start postfix.service
systemctl enable postfix.service

到此完成配置,其它服务已经能够通过 postfix 发送提醒邮件。
由于只发邮件,所以防火墙不必开启 POP3、SMTP 等服务端口。

学习自:https://www.ifshow.com/centos-7-install-postfix-for-sending-e-mail-alerts/

邮件服务器很有必要。用来及时通知管理员服务器警报情况

后面再来补充一个代码报错实例

Centos 7.1搭建postfix 邮件系统

Centos 7.1搭建postfix 邮件系统

学习一个服务的流程;

1、此服务器的概述:名字,功能,特点,端口号

2、安装

3、配置文件的位置

4、服务启动关闭脚本,查看端口

5、此服务的使用方法

6、修改配置文件,实战举例

7、服务的安全

8、排错(从下到上,从内到外)

9、模拟错误<对服务的原理要精通>

背景介绍;

RHEL5默认,地位已失

地位失守原因:

 第一个重要的缺点是它的安全性较差,这是因为当其作者Eric Allman最初开始写作这个软件的时候,Internet的用户还很少,因而安全性并不没有得到大家的重视。

由于邮件系统需要处理的是外部发送来的各种各样的信息,甚至包含一些恶意数据,然而sendmail在大多数系统中都是以root身份运行,一旦出现问题,就会对系统安全造成严重影响。在这种情况下,要防止出现安全问题,仅仅依赖程序本身是不可取的,应该从系统结构出发,使程序拥有的特殊权限限制到最小。

第二个,使用Sendmail还会遇到的另一个问题是它的设置相当复杂,对于使用缺省设置来收发电子邮件,问题并不存在。当管理员打算进行一些特殊设置,以便利用Sendmail提供的复杂邮件处理能力时,就不得不面对复杂的宏和正则表达式。

Qmail可以替代Sendmail

Qmail,为了解决sendmail的安全问题,整个系统结构需要重新设计。基本的原则是将系统划分为不同的模块,有负责接收外部邮件的,有管理缓冲目录中待发送的邮件队列的,有将邮件发送到远程服务器或本地用户的。Qmail就是按照这个原则进行的设计,它由多个不同功能的小程序组成,只有必要的程序才是setuid程序(即以root用户权限执行),这样就减少了安全隐患,并且由于这些程序都比较简单一些,因此就可以达到较高的安全性。Qmail已经许多年没有更新了,用户已经习惯于通过第三方的插件及补丁来使qmail增加新的功能.

postfix 介绍:

另一种替换软件:Postfix 可以替代sendmail
postfix同样也是采用了模块化的方式,但与Qmail不同的是,Postfix使用了一个主控进程进行监控。Postfix在很多方面都考虑到了安全问题,它甚至不向root分发电子邮件,以避免以root身份读写文件或启动外部程序。考虑到它的作者Wietse Venema曾编写了著名的安全软件TcpWrapper,Postfix的安全性是非常值得信赖的。

Postfix的性能也非常不错,甚至在Qmail作者自己进行的测试中也表明,Postfix的性能和Qmail基本相当。postfix在性能上大约比sendmail快三倍

官网:http://www.postfix.org/

logo

作者:Wietse Venema

作者介绍:http://www.porcupine.org/wietse/

前面我们说的都是邮件发送服务器

接下来我们看看邮件接收服务器

Dovecot:邮件接收服务器:

Dovecot是一个开源的 IMAP 和 POP3 邮件服务器,支持 Linux/Unix 系统。

POP / IMAP4是 MUA 从邮件服务器中读取邮件时使用的协议。

POP3是从邮件服务器中下载邮件存起来,IMAP 则是将邮件留在服务器端直接对邮件进行管理、操作。比POP3更先进。

由 Timo Sirainen 开发,最初发布于 2002年7月。作者将安全性考虑在第一,所以 Dovecot 在安全性方面比较出众。

IMAP4是TCP/IP协议族中的一员,现在的版本是“IMAP第四版第一次修订版”。

一个完整的邮件服务器由以下内容构成:

postfix(作为发送邮件服务器)+dovecot(作为接收邮件服务器)+MysqL(作为数据库)

25端口:SMTP协议。 发送邮件

是本地邮件传输协议,与SMTP类似,但不支持邮件队列(queue),主要应用于非广域网的邮件网关。

110端口:POP3协议

是本地邮件传输协议,与SMTP类似,但不支持邮件队列(queue),主要应用于非广域网的邮件网关。

143:IMAP

IMAP: (InternetMail Access Protocol Internet邮件访问协议) 。IMAP是斯坦福大学在1986年开发的一种邮件获取协议。它的主要作用是邮件客户端(例如Outlook)可以通过这种协议从邮件服务器上获取邮件的信息,下载邮件等。

当前的权威定义是RFC3501。IMAP协议运行在TCP/IP协议之上,使用的端口是143。它与POP3协议的主要区别是用户可以不用把所有的邮件全部下载,可以通过客户端直接对服务器上的邮件进行操作。两者之前的区别

POP3协议允许电子邮件客户端下载服务器上的邮件,但是在客户端的操作(如移动邮件、标记已读等),不会反馈到服务器上,比如通过客户端收取了邮箱中的3封邮件并移动到其他文件夹,邮箱服务器上的这些邮件是没有同时被移动的 。

而IMAP提供webmail 与电子邮件客户端之间的双向通信,客户端的操作都会反馈到服务器上,对邮件进行的操作,服务器上的邮件也会做相应的动作。

邮件功能组件

MUA:邮件用户代理(Mail User Agent) 收邮件

MTA:邮件传输代理(Mail Transfer Agent) 发邮件

rhel5默认采用sendmail做为MTA,rhel6则采用postfix

MDA:邮件递送代理(Mail Delivery Agent)


名称

全名

基于协议

作用

常见软件

MUA

Mail User Agent用户邮件代理

替用户收发邮件的

Outlook Foxmail Thunderbird mutt

MTA

Mail Transfer Agent邮件传输代理

SMTP

服务器中接受邮件

Sendmail qmail postfix(IBM) exchange

MDA

Mail Deliver Agent邮件投递代理

把SMTP收到的邮件投递的用户邮箱

Procmail maildrop

MRA

Mail Retrival Agent邮件检索代理

POP3/IMAP

帮用户去邮箱取邮件

dovecot courier-imap cyrus-imap

工作原理图

Centos 7.1搭建postfix 邮件系统

搭建postfx服务端

[root@post-test ~]# hostname
postfix-server
[root@postfix-server ~]# rpm -qa |grep sendmail
[root@postfix-server ~]# yum remove sendmail -y

[root@postfix-server ~]# alternatives --config mta

共有 1 个提供“mta”的程序。

选项 命令
-----------------------------------------------
*+ 1 /usr/sbin/sendmail.postfix

按 Enter 保留当前选项[+],或者键入选项编号: #如果有多个输入数字进行选择

[root@postfix-server ~]alternatives --display mta#查看所有详细的版本

[root@postfix-server ~]#yuminstall postfix –y# postfix服务的主程序包,服务器端必须安装该

[root@postfix-server ~]#yuminstall dovecot –y#接收邮件软件包。 安装在服务端用于测试收邮件。 安装客端用于收邮件。

[root@postfix-server ~] #vim /etc/postfix/main.cf

[root@postfix-server ~] # vim/var/log/maillog

[root@postfix-server ~]#service postfix start

[root@postfix-server ~]#lsof -i :25

COMMAND PID USERFD TYPE DEVICE SIZE/OFF NODENAME

master 2336 root12u IPv4 132160t0 TCP localhost:smtp (LISTEN)

master 2336 root13u IPv6 132180t0 TCP localhost:smtp (LISTEN)

服务的使用方法:

linux:

发送:

[root@postfix-server ~]# mail -s 'Postfix'1684067131@qq.com < /etc/passwd

-s:指定邮件主题名

接收:

mail

windows:

通过浏览器访问或 foxmail


案例一;

配置postfix邮件服务器,实现邮件发送功能。实现给邮箱:1684067131@qq.com 发送邮件。

1)修改主机名和对应关系:

[root@postfix-server~]# hostname

xuegod63.cn

[root@postfix-server ~]# cat /etc/hosts
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
postfix-server 172.16.1.201

2.修改postfix服务配置文件

[root@postfix-server ~]#vim /etc/postfix/main.cf

queue_directory= /var/spool/postfix#队列目录,也是运行的根目录

mydomain =postfix-server#指定邮件域,接收用来识别的

myhostname= postfix-server#发送邮件的主机名

mynetworks= 192.168.1.0/24,127.0.0.0/8#指定允许使用的ip地址段

myorigin =$mydomain#发信地址,此设置显示为@postfix-server

inet_interfaces= all#对外提供MTA服务设置为监听所有网卡,默认只监听本地

#inet_interfaces= localhost #注释掉,这个是只监听本地的

mydestination= $myhostname,localhost.$mydomain,localhost,$mydomain

mynetworks_style= subnet #允许转发的来源网段,可选subnet子网,class网段,host本机

local_recipient_maps=//209行,把前面的注释拿掉

relay_domains= $mydestination#允许转发的目标域

alias_maps= hash:/etc/aliases#对某个用户发,文件中的用户都可以收到邮件

alias_database= hash:/etc/aliases

smtpd_banner= $myhostname ESMTP "postfix mail server"#自定服务器信息


3.启动postfix服务;

[root@postfix-server ~]#servicepostfix restart

1)测试给123456789@qq.com发送邮件:

[root@xuegod63 ~]# mail -s 'Postfix'123456789@qq.com< /etc/postfix/main.cf

由于要经过很多域名解析发送中转,所以会有些延迟

-s:邮件主题

#

[root@postfix-server ~]#mail

HeirloomMail version 12.4 7/29/08. Type ? forhelp.

"/var/spool/mail/root":12 messages 1 new 2 unread

>N 12 Mail Delivery System Sun Nov 29 21:14 752/29445 "UndeliveredMail Returned to S"

&

没有发送出去,经验证是网络ip的问题

http://www.anti-spam.org.cn/反垃圾邮件联盟,看看你的ip是否被拉入黑名单

用别的地方的一台机器,一样的配置文件,可以发送

[root@postfix~]# mail -s 'Postfix' 123567890@qq.com </etc/postfix/main.cf

Centos 7.1搭建postfix 邮件系统

1.我们怎样才能让我们的邮件服务器给别人发送邮件不显示垃圾邮件?

需要为邮件服务器添加DNS解析

虽然不加DNS解析也能把邮件发出去,但会被大多数邮件服务器当作垃圾邮件。根据我们的实际经验,需要添加三条DNS解析记录:A记录、MX记录、TXT记录比如域名cnblogs.info,对应的DNS记录如下

Centos 7.1搭建postfix 邮件系统

例2:配置postfix给一个人发送邮件多个人可以收到

需求:

我们先创建2个用户,创建一个组HA,当我们给HA送邮件的时候,alice和bob两个用户可以收到邮件

别名功能

1)添加测试用户:

[root@postfix-server ~]# groupadd HA

[root@postfxi-server ~]# useradd alice

[root@postfix-server ~]# echo "123456" | passwd --stdinalice

[root@postfix-server ~]# useradd bob

[root@postfix-server~]# echo "123456" | passwd --stdin bob

[root@postfix-server~]# vim /etc/aliases

HA: alice,bob

[root@postfix-server ~]# service postfixrestart

3)发送测试邮件:

[root@postfix-server ~]# mail HA

Subject: Test

This is a Test-mail

lllloo

kllll

lll

EOT按ctrl-D结束输入

4)切换用户查看:

[root@postfix-server ~]# su - alice

[alice@postfix-server ~]$ mail

配置dovecot服务器,实现发邮件和接收邮件

  • 修改dovecot配置文件:

[root@postfix-server ~]# vim /etc/dovecot/dovecot.conf

protocols = imap pop3 lmtp#启用,lmtp被淘汰的地步。可能不被支持,不用就删掉

login_trusted_networks = 192.168.1.0/24//指定允许登录的网段地址

或login_trusted_networks = 0.0.0.0设置为四个零,允许所有网络

[root@postfix-server ~]# grep -v '^#' /etc/dovecot/dovecot.conf |grep-v '^$' |grep -v '#'

protocols= imap pop3 lmtp

login_trusted_networks= 192.168.1.0/24

dict {

}

!includeconf.d/*.conf

  • 设置邮件存放目录:

[root@postfix-server~]# vim/etc/dovecot/conf.d/10-mail.conf

mail_location = mBox:~/mail:INBox=/var/mail/%u#指定邮件的位置

  • 重启dovecot服务

[root@postfix ~]# service dovecot restart

  • 修改创建用户模板文件,使用户创建时自动生成mail存放目录

[root@postfix ~]# vim /etc/skel/.bash_profile

if[ ! -d ~/mail/.imap/INBox ] ; then

mkdir -p ~/mail/.imap/INBox

fi

[root@postfix-server ~]# source .bash_profile

5)测试:

先创建用户

[root@postfix-server~]# useradd alice

[root@postfix-server~]# echo alice:123456 |chpasswd

[root@postfix-server~]# useradd bob

[root@postfix ~]# echobob:123456 |chpasswd

测试发邮件

测试发邮件:

mail发邮件三种用法

1:以文件中的内容为邮件内容发信

[root@postfix-server ~]# su - alice

[alice@postfix-server ~]$ mail -s'Posfix1' bob@postfix-server < /etc/hosts

2:手动输入内容作为发送内容

[alice@postfix-server ~]$ echo"2222222222" | mail -s 'Postfix2' bob@postfix-server

3:手动输入一串作为发送内容

[alice@postfix-server~]$ mail -s 'Postfix3' bob@postfix-server

yyyuuu

hhhhhkkk

jjjnnnn

EOT

通过mail命令查看邮件:

[root@postfix-server~]# su - bob

[bob@postfix-serve~]$ mail

&#mail命令的提示符为 &

& 1#输入数字1,查看第一封邮件

& h#查看邮件列表

& l #查看所有支持的命令

& d 2#删除第二个邮件; d 2-4 删除第2-4的邮件

&?#查看 所有用法。

CentOS 7.2 部署邮件服务器(Postfix)

CentOS 7.2 部署邮件服务器(Postfix)

一、Postfix简介

  • Postfix 是一种电子邮件服务器,它是由任职于IBM华生研究中心(T.J. Watson Research Center)的荷兰籍研究员Wietse Venema为了改良sendmail邮件服务器而产生的。最早在1990年代晚期出现,是一个开放源代码的软件。
  • Postfix 官方网站:http://www.postfix.org/
  • Postfix 下载地址:http://www.postfix.org/download.html

二、Postfix安装

  • 安装Postfix以配置SMTP服务器

[1] 即使CentOS系统安装了[最小安装],也会安装Postfix,但如果Postfix不安装,请先安装它,如下所示。

[root@linuxprobe ~]# yum -y install postfix

[2] 此示例显示配置SMTP-Auth以使用Dovecot的SASL函数。

[root@linuxprobe ~]# vi /etc/postfix/main.cf
# line 75: uncomment and specify hostname

myhostname = linuxprobe.srv.world
# line 83: uncomment and specify domain name

mydomain = srv.world
# line 99: uncomment

myorigin = $mydomain
# line 116: change

inet_interfaces = all
# line 164: add

mydestination = $myhostname,localhost.$mydomain,localhost,$mydomain
# line 264: uncomment and specify your local network

mynetworks = 127.0.0.0/8,10.0.0.0/24
# line 419: uncomment (use mailBoxdir)

home_mailBox = mailBox/
# line 574: add

smtpd_banner = $myhostname ESMTP
# add follows to the end

# limit an email size for 10M

message_size_limit = 10485760

# limit a mailBox for 1G

mailBox_size_limit = 1073741824
# for SMTP-Auth

smtpd_sasl_type = dovecot
smtpd_sasl_path = private/auth
smtpd_sasl_auth_enable = yes
smtpd_sasl_security_options = noanonymous
smtpd_sasl_local_domain = $myhostname
smtpd_recipient_restrictions = permit_mynetworks,permit_auth_destination,permit_sasl_authenticated,reject

[root@linuxprobe ~]# systemctl restart postfix
[root@linuxprobe ~]# systemctl enable postfix

[3]如果Firewalld正在运行,请允许SMTP服务。 SMTP使用25 / TCP。

[root@dlp ~]# firewall-cmd --add-service=smtp --permanent
success
[root@dlp ~]# firewall-cmd --reload
success

三、Dovecot 安装

  • 安装Dovecot以配置POP / IMAP服务器

[1] 安装Dovecot.

[root@linuxprobe ~]# yum -y install dovecot

[2] 此示例显示配置为向Postfix提供SASL功能 .

[root@linuxprobe ~]# vi /etc/dovecot/dovecot.conf
# line 24: uncomment
protocols = imap pop3 lmtp
# line 30: uncomment and change ( if not use IPv6 )
listen = *
[root@linuxprobe ~]# vi /etc/dovecot/conf.d/10-auth.conf
# line 10: uncomment and change ( allow plain text auth )
disable_plaintext_auth = no
# line 100: add
auth_mechanisms = plain login
[root@linuxprobe ~]# vi /etc/dovecot/conf.d/10-mail.conf
# line 30: uncomment and add
mail_location = maildir:~/Maildir
[root@linuxprobe ~]# vi /etc/dovecot/conf.d/10-master.conf
# line 96-98: uncomment and add like follows
# Postfix smtp-auth
unix_listener /var/spool/postfix/private/auth {
    mode = 0666
    user = postfix
    group = postfix
}
[root@linuxprobe ~]# vi /etc/dovecot/conf.d/10-ssl.conf
# line 8: change (not require SSL)
ssl = no

[root@linuxprobe ~]# systemctl start dovecot
[root@linuxprobe ~]# systemctl enable dovecot

[3] 如果Firewalld正在运行,请允许POP / IMAP服务。 POP使用110 / TCP,IMAP使用143 / TCP.

[root@vdevops ~]# firewall-cmd --add-port={110/tcp,143/tcp} --permanent
success
[root@vdevops ~]# firewall-cmd --reload
success

四、SSL设置

  • 配置SSL以加密连接

[1] 首先创建证书,传送门:http://www.jb51.cc/article/p-pukuckix-qq.html
[2] 为SSL配置Postfix和Dovecot。

# add to the end
smtpd_use_tls = yes
smtpd_tls_cert_file = /etc/pki/tls/certs/server.crt
smtpd_tls_key_file = /etc/pki/tls/certs/server.key
smtpd_tls_session_cache_database = btree:/etc/postfix/smtpd_scache
[root@linuxprobe ~]# vi /etc/postfix/master.cf
# line 26-28: uncomment
smtps       inet   n       -       n       -       -       smtpd
  -o syslog_name=postfix/smtps
  -o smtpd_tls_wrappermode=yes
[root@linuxprobe ~]# vi /etc/dovecot/conf.d/10-ssl.conf
# line 8: change
ssl = yes
# line 14,15: specify certificates
ssl_cert = </etc/pki/tls/certs/server.crt
ssl_key = </etc/pki/tls/certs/server.key
[root@linuxprobe ~]# systemctl restart postfix dovecot

[3] 如果Firewalld正在运行,请允许SMTPS / POP3S / IMAPS服务。 SMTPS使用465 /
TCP,POP3S使用995 / TCP,IMAPS使用993 / TCP。

[root@vdevops ~]# firewall-cmd --add-service={pop3s,imaps} --permanent
success
[root@vdevops ~]# firewall-cmd --add-port=465/tcp --permanent
success
[root@vdevops ~]# firewall-cmd --reload
success

邮件日志报告:pflogsumm

  • 安装pflogsumm这是Postfix日志报告工具

[1] 安装postfix-perl-scripts包 .

[root@linuxprobe ~]# yum -y install postfix-perl-scripts
# generate log summary for yesterday
[root@linuxprobe ~]# perl /usr/sbin/pflogsumm -d yesterday /var/log/maillog
Postfix log summaries for Jul 14
Grand Totals ------------
messages
 2 received
 5 delivered
 0 forwarded
 0 deferred
 0 bounced
 0 rejected (0%)
 0 reject warnings
 0 held
 0 discarded (0%)

 2879 bytes received
 6572 bytes delivered
 1 senders
 1 sending hosts/domains
 2 recipients
 2 recipient hosts/domains
Per-Hour Traffic Summary ------------------------
 time received delivered deferred bounced rejected
 --------------------------------------------------------------------
 0000-0100 0 0 0 0 0
 0100-0200 0 0 0 0 0
 0200-0300 0 0 0 0 0
 0300-0400 0 0 0 0 0
 0400-0500 0 0 0 0 0
 0500-0600 0 0 0 0 0
 0600-0700 0 0 0 0 0
 0700-0800 0 0 0 0 0
 0800-0900 0 0 0 0 0
 0900-1000 0 0 0 0 0
 1000-1100 2 5 0 0 0
 1100-1200 0 0 0 0 0
 1200-1300 0 0 0 0 0
 1300-1400 0 0 0 0 0
 1400-1500 0 0 0 0 0
 1500-1600 0 0 0 0 0
 1600-1700 0 0 0 0 0
 1700-1800 0 0 0 0 0
 1800-1900 0 0 0 0 0
 1900-2000 0 0 0 0 0
 2000-2100 0 0 0 0 0
 2100-2200 0 0 0 0 0
 2200-2300 0 0 0 0 0
 2300-2400 0 0 0 0 0

Host/Domain Summary: Message Delivery --------------------------------------
 sent cnt bytes defers avg dly max dly host/domain
 -------- ------- ------- ------- ------- -----------
 3 4119 0 0.4 s 0.8 s srv.world
 2 2453 0 0.1 s 0.1 s mail.srv.world

Host/Domain Summary: Messages Received ---------------------------------------
 msg cnt bytes host/domain
 -------- ------- -----------
 2 2879 mail.srv.world

Senders by message count ------------------------
 2 cent@mail.srv.world

Recipients by message count ---------------------------
 3 redhat@srv.world
 2 cent@mail.srv.world

Senders by message size -----------------------
 2879 cent@mail.srv.world

Recipients by message size --------------------------
 4119 redhat@srv.world
 2453 cent@mail.srv.world

message deferral detail: none
message bounce detail (by relay): none
message reject detail: none
message reject warning detail: none
message hold detail: none
message discard detail: none
smtp delivery failures: none
Warnings --------
 tlsmgr (total: 6)
 3 redirecting the request to postfix-owned data_directory /var/li...
 3 request to update table btree:/etc/postfix/smtpd_scache in non-...

Fatal errors: none
Panics: none
Master daemon messages ----------------------
 4 daemon started -- version 2.10.1,configuration /etc/postfix
 3 terminating on signal 15
 1 reload -- version 2.10.1,configuration /etc/postfix

[root@linuxprobe ~]# crontab -e
# 发送邮件日志摘要在AM每天1:00到根
00 01 * * * perl /usr/sbin/pflogsumm -e -d yesterday /var/log/maillog | mail -s 'Logwatch for Postfix' root

今天的关于centos配置postfix邮件服务centos部署邮件服务器的分享已经结束,谢谢您的关注,如果想了解更多关于centos 7 postfix配置163邮箱发送邮件、Centos 7 安装 Postfix 用于发送提醒邮件、Centos 7.1搭建postfix 邮件系统、CentOS 7.2 部署邮件服务器(Postfix)的相关知识,请在本站进行查询。

本文标签: