注:大部分内容来自互联网,我做了一点整理和归纳。
1.MX记录
添加
mx mail.xxx.com. 10
a mail ipaddress
确保MX记录生效
#host -t mx xxx.com
xxx.com mail is handled by 10 mail.xxx.com. ← 确认MX记录生效
2.Postfix
安装
#yum -y install postfix
对Postfix进行配置。
[root@sample ~]# vi /etc/postfix/main.cf← 编辑Postfix的配置文件
#myhostname = host.domain.tld← 找到此行,将等号后面的部分改写为主机名
↓
myhostname = sample.centospub.com← 变为此状态,设置系统的主机名
#mydomain = domain.tld← 找到此行,将等号后面的部分改写为域名
↓
mydomain = centospub.com← 变为此状态,设置域名(我们将让此处设置将成为E-mail地址“@”后面的部分)
#myorigin = $mydomain← 找到此行,将行首的#去掉
↓
myorigin = $mydomain← 变为此状态,将发信地址“@”后面的部分设置为域名(非系统主机名)
inet_interfaces = localhost← 找到此行,将“localhost”改为“all”
↓
inet_interfaces = all← 变为此状态,接受来自所有网络的请求
mydestination = $myhostname, localhost.$mydomain, localhost← 找到此行,在行为添加“$mydomain”
↓
mydestination = $myhostname, localhost.$mydomain, localhost, $mydomain← 变为此状态,指定发给本地邮件的域名
#relay_domains = $mydestination← 找到此行,将行首的#去掉
↓
relay_domains = $mydestination← 变为此状态,定义允许转发的域名
#mynetworks = 168.100.189.0/28, 127.0.0.0/8← 找到此行,依照自己的内网情况修改
↓
mynetworks = 168.100.189.0/28, 127.0.0.0/8← 变为此状态,指定内网和本地的IP地址范围
#home_mailbox = Maildir/← 找到这一行,去掉行首的#
↓
home_mailbox = Maildir/← 变为此状态,指定用户邮箱目录
# SHOW SOFTWARE VERSION OR NOT
#
# The smtpd_banner parameter specifies the text that follows the 220
# code in the SMTP server’s greeting banner. Some people like to see
# the mail version advertised. By default, Postfix shows no version.
#
# You MUST specify $myhostname at the start of the text. That is an
# RFC requirement. Postfix itself does not care.
#
#smtpd_banner = $myhostname ESMTP $mail_name
#smtpd_banner = $myhostname ESMTP $mail_name ($mail_version)← 找到这一行,接此行添加如下行:
smtpd_banner = $myhostname ESMTP unknow← 添加这一行,不显示SMTP服务器的相关信息
在配置文件的文尾,添加如下行:
smtpd_sasl_auth_enable = yes← 服务器使用SMTP认证
smtpd_sasl_local_domain = $myhostname← 指定SMTP认证的本地域名(主机名)
smtpd_sasl_security_options = noanonymous ← 不允许匿名的方式认证
smtpd_recipient_restrictions = permit_mynetworks, permit_sasl_authenticated, reject_unauth_destination
smtpd_sasl_security_restrictions = permit_mynetworks, permit_sasl_authenticated, reject_unauth_destination←(very important)
message_size_limit = 15728640← 规定邮件最大尺寸为15MB
配置SMTP认证
[root@office-gw ~]# cat /usr/lib/sasl2/smtpd.conf
pwcheck_method: saslauthd
[root@office-gw ~]# cat /etc/sysconfig/saslauthd
# Directory in which to place saslauthd's listening socket, pid file, and so
# on. This directory must already exist.
SOCKETDIR=/var/run/saslauthd
# Mechanism to use when checking passwords. Run "saslauthd -v" to get a list
# of which mechanism your installation was compiled with the ablity to use.
MECH=shadow
# Additional flags to pass to saslauthd on the command line. See saslauthd(8)
# for the list of accepted flags.
FLAGS=
建立用户的邮箱目录
首先建立用户模板下的邮箱目录,以便于建立新用户时,相应用户的邮箱目录自动被建立。
[root@sample ~]# mkdir /etc/skel/Maildir← 在用户模板下建立用户邮箱目录
[root@sample ~]# chmod 700 /etc/skel/Maildir← 设置用户邮箱目录属性为700
然后再为已经存在的用户建立相应邮箱目录。
[root@sample ~]# mkdir /home/centospub/Maildir ← 为用户(这里以centospub用户为例)建立邮箱目录
[root@sample ~]# chmod 700 /home/centospub/Maildir ← 设置该用户邮箱目录属性为700
[root@sample ~]# chown centospub. /home/centospub/Maildir ← 设置该用户邮箱目录为该用户所有
测试smtp验证
#testsaslauthd -u test -p 12345
0: OK "Success."
关闭sendmail服务及设置默认MTA
因为在用Postfix作为SMTP服务器的前提下,我们不准备再用sendmail,所以将sendmail服务关掉,以确保安全及节省系统资源。
[root@sample ~]# /etc/rc.d/init.d/sendmail stop ← 关闭sendmail服务
Shutting down sendmail: [ OK ]
Shutting down sm-client: [ OK ]
[root@sample ~]# chkconfig sendmail off ← 关闭sendmail自启动
[root@sample ~]# chkconfig –list sendmail ← 确认sendmail自启动已被关闭(都为off就OK)
sendmail 0:off 1:off 2:off 3:off 4:off 5:off 6:off
然后再将默认的MTA设置为Postfix。
[root@sample ~]# alternatives –config mta ← 设置默认MTA
There are 2 programs which provide ‘mta’.
Selection Command
———————————————–
*+ 1 /usr/sbin/sendmail.sendmail ← 当前状态:sendmail为默认MTA
2 /usr/sbin/sendmail.postfix
Enter to keep the current selection[+], or type selection number: 2 ← 在这里输入2,使Postfix成为默认MTA
最后启动相应的服务器
#service postfix start
#service saslauthd start
修改chkconfig启动服务列表
验证sendmail服务
telnet localhost 25 //输入helo localhost 此时应该有LOGIN PLAIN的字样,即表示SMTP认证设置成功。
[root@centos5 mail]# telnet localhost 25
Trying 127.0.0.1...
Connected to localhost.localdomain (127.0.0.1).
Escape character is '^]'.
220 centos5 ESMTP Sendmail 8.13.8/8.13.8; Thu, 6 May 2010 06:21:29 +0800
helo localhost
250 centos5 Hello localhost.localdomain [127.0.0.1], pleased to meet you
mail from:<test@localmail.com>
250 2.1.0 <test@localmail.com>… Sender ok
rcpt to:<testreceive@163.com>
(要测试向外发送邮件就填写网络上存在的邮件地址)
250 2.1.5 <testreceive@163.com>... Recipient ok
data
354 Enter mail, end with "." on a line by itself
From: alin
To: alin
Subject: Hello
test
.
250 2.0.0 o45MLTcH005157 Message accepted for delivery
quit
221 2.0.0 centos5 closing connection
Connection closed by foreign host.
3,POP服务器
POP / IMAP 是 MUA 从邮件服务器中读取邮件时使用的协议。其中,与 POP3 是从邮件服务器中下载邮件比起来,IMAP4 则是将邮件留在服务器端直接对邮件进行管理、操作。这里,我们用 Dovecot 来实现对 POP3 及 IMAP4 等协议支持的邮件接收服务器的搭建。
Dovecot 是一个比较新的软件,由 Timo Sirainen 开发,最初发布于 2002年7月。作者将安全性考虑在第一,所以 Dovecot 在安全性方面比较出众。另外,Dovecot 支持多种认证方式,所以在功能方面也比较符合一般的应用。
---------------------------------------------------------------------------------------------------------------------------------------------------
首先,安装 Dovecot
[root@sample ~]# yum -y install dovecot
修改相应配置文件,配置 Dovecot
[root@sample ~]# vi /etc/dovecot.conf ← 编辑Dovecot 的配置文件
#protocols = imap imaps ← 找到这一行,将协议设置为imap与pop3
protocols = imap pop3 ← 变为此状态
#default_mail_env = ← 找到这一行,定义邮件目录
default_mail_env = maildir:~/Maildir ← 定义邮件目录为用户目录下的Maildir目录
最后,启动 Dovecot ,并将其设置为自启动。
[root@sample ~]# chkconfig dovecot on ← 设置Dovecot为自启动
4.添加防火墙规则
由于 POP3 协议与 IMAP4 协议要分别用到110号和143号端口,所以在启动服务前,配置防火墙,开通这两个端口。
[root@sample ~]# vi /etc/sysconfig/iptables ← 编辑防火墙规则
-A RH-Firewall-1-INPUT -m state --state NEW -m tcp -p tcp --dport 25 -j ACCEPT ← 找到此行,接着添加如下两行:
-A RH-Firewall-1-INPUT -m state --state NEW -m tcp -p tcp --dport 110 -j ACCEPT ← 允许POP使用的110号端口
-A RH-Firewall-1-INPUT -m state --state NEW -m tcp -p tcp --dport 143 -j ACCEPT ← 允许IMAP使用的143号端口
[root@sample ~]# /etc/rc.d/init.d/iptables restart ← 重新启动防火墙,使新的设置生效
Flushing firewall rules: [ OK ]
Setting chains to policy ACCEPT: filter [ OK ]
Unloading iptables modules: [ OK ]
Applying iptables firewall rules: [ OK ]
分享到:
相关推荐
CentOS5.3安装postfix+extmail邮件系统
CentOS 5.3安装Postfix+Extmail邮件服务器.pdf
在CentOS中,默认的邮件服务器(SMTP方面)是sendmail,但sendmail有若干的缺点,比如,配置复杂、安全漏洞曾被多次发现--并且依然存在隐患、邮件发送速度慢等等,这里就不再一一叙述。而另一个被广泛应用于邮件服务...
CentOS 5.2 安装基于postfix的全功能邮件服务
在centos7环境下搭建的邮件服务器,centos7+postfix+dovecot+squirrelmail
此资源是关于在linux系统(Centos5)环境下安装搭建postfix邮件服务器,文档详尽是不可多得的资源。
centos6.6 Oracle11G安装文档,能够帮助实施和初学linux成员快速掌握oracle的安装。
Centos5.4 postfix extmail 搭建邮件系统
上传centos7安装mysql的文档及软件的安装包以备后续使用
centos 6.7安装详细过程
postfix 安装的一些参数,, mysql 做数据库
在本指南中,你将学习如何在 CentOS 8 上安装和配置 Postfix。 实验室设置: 系统:CentOS 8 服务器 IP 地址:192.168.1.13 主机名:server1.crazytechgeek.info(确保域名指向服务器的 IP) 步骤 1)更新系统 ...
oracle 在centos下安装配置文档
CentOS 6.3安装文档 word版
自己整理的在VMware下安装centos5版本的详细步骤,和配置mysql apache 以及phpmyadmin的详细方法,值得下载!!!超值
centos7.0安装mysql centos7.0安装mysql centos7.0安装mysql
centos postfix extmail 安装和常见问题
CentOS5下使用Postfix搭建邮件服务器的详细教程
svn+apache centos下安装文档svn+apache centos下安装文档
centos下搭建postfix邮件服务器[文].pdf