CentOS 使用PostFix搭建邮件服务器

搭建环境:

关于PostFix是什么以及邮件服务器接受发送邮件流程网上有很多文章,这里就不再写了,这里只记录如何搭建邮件服务器,使用PostFix接受发送邮件

CentOS6.8 32位,postfix-2.6.6

配置工具:

yum install postfix

 

postfix主要配置文件在/etc/postfix/main.cf中

修改后内容如下(yuming.com改为自己的域名)

queue_directory = /var/spool/postfix
command_directory = /usr/sbin
daemon_directory = /usr/libexec/postfix
data_directory = /var/lib/postfix
mail_owner = postfix
myhostname = localhost 
mydomain = yuming.com 
myorigin = $mydomain
inet_interfaces = all
inet_protocols = ipv4 
mydestination = $myhostname, localhost.$mydomain, localhost, yuming.com
unknown_local_recipient_reject_code = 550
mynetworks_style = host
mynetworks = 127.0.0.0/8,192.168.100.0/24,hash:/etc/postfix/access
relay_domains = $mydestination
alias_maps = hash:/etc/aliases
alias_database = hash:/etc/aliases
debug_peer_level = 2
debugger_command =
     PATH=/bin:/usr/bin:/usr/local/bin:/usr/X11R6/bin
     ddd $daemon_directory/$process_name $process_id & sleep 5
sendmail_path = /usr/sbin/sendmail.postfix
newaliases_path = /usr/bin/newaliases.postfix
mailq_path = /usr/bin/mailq.postfix
setgid_group = postdrop
html_directory = no
manpage_directory = /usr/share/man
sample_directory = /usr/share/doc/postfix-2.6.6/samples
readme_directory = /usr/share/doc/postfix-2.6.6/README_FILES

 

邮件别名配置文件

在 /etc/aliases 文件中,你会发现有如下的文件内容

bin:            root
daemon:         root
adm:            root
lp:             root
sync:           root
shutdown:       root
halt:           root
mail:           root
news:           root
uucp:           root

 

文件中的意思是,如果有邮件发送到左边用户的邮箱内,则会由右边的邮件帐号来接收

启动服务

postmap hash:/etc/postfix/access
postalias hash:/etc/aliases
检查是否有错误
/etc/init.d/postfix check
启动服务
service postfix start
或者
service postfix restart
查看是否成功
netstat -tlunp | grep ':25'

开放端口

开放25端口,不然发送不出去

iptables -A INPUT -p tcp --dport 25 -j ACCEPT
iptables -A OUTPUT -p tcp --sport 25 -j ACCEPT

测试发送邮件

yum install mail  #安装邮件客户端
echo hello > mail.txt #将需要发送的邮件内容写入一个文件
mail -s "Hello" reyzal@163.com < mail.txt #发送到reyzal@163.com邮箱

image

测试接收邮件

使用mail即可查看邮件

image

结束

posted @ 2017-03-06 18:01  reyzal  阅读(590)  评论(0编辑  收藏  举报