扫二维码与项目经理沟通
我们在微信上24小时期待你的声音
解答本文疑问/技术咨询/运营咨询/技术建议/互联网交流
wget http://sourceforge.net/p
目前累计服务客户近1000家,积累了丰富的产品开发及服务经验。以网站设计水平和技术实力,树立企业形象,为客户提供成都网站设计、成都网站建设、外贸网站建设、网站策划、网页设计、网络营销、VI设计、网站改版、漏洞修补等服务。成都创新互联始终以务实、诚信为根本,不断创新和提高建站品质,通过对领先技术的掌握、对创意设计的研究、对客户形象的视觉传递、对应用系统的结合,为客户提供更好的一站式互联网解决方案,携手广大客户,共同发展进步。
SMTP:(Simple Mail Transfer Protocol)即简单邮件传输协议
POP3:邮局协议 IMAP4:internet mail access protocol 互联网邮件访问协议
SASL:simple Authentication Secure layer 简单安全认证层 (版本v1,v2目前主流v2版本)
MDA:邮件投递代理(procmail,maildrop)
MUA:邮件用户代理(mutt)
mail relay: 邮件中继
MTA:报文传输代理 (sendmail,postfix,qmail,exim)
Postfix的配置文件:
postfix模块化:
master:/etc/postfix/master.cf 主进程配置文件
mail:/etc/postfix/main.cf 主配置文件(相关配置的主配置文件)
格式:参数 = 值:参数必须写在绝对行首(即行首不能有空格),以空白开头的行被认
为是上一行的延续(即行首有空白的行都是上一行没有写完的内容)。
postconfig: 可以直接配置修改postfix的主配置文件
-d: 显示默认的配置
-n: 修改了的配置
-m: 显示支持的查找表类型
-A:显示支持的SASL客户端插件类型
-e PARMATER=VALUE: 更改某参数配置信息,并保存至main.cf主配置文件中
-a: 服务器端支持的SASL插件类型
smtp状态码:
1xx:纯信息
2xx:正确信息
3xx:上一步操作尚未完成,需要继续补充
4xx:暂时性错误
5xx:永久性错误
smtp协议命令:
helo (smtp协议)
ehlo (esmtp协议)
mail from: 指定发件人
rcpt to:指定收件人
data 输入正文
Subject: 邮件主题
邮件正文以.结束
quit退出邮件
[root@lamp ~]#ls
postfix-2.10.10.tar.gz
[root@lamp ~]# tar xf postfix-2.10.10.tar.gz #解压postfix软件
[root@lamp ~]# ls
postfix-2.10.10 postfix-2.10.10.tar.gz
[root@lamp ~]# cd postfix-2.10.10 #进入解压目录
[root@lamp postfix-2.10.10]# groupadd -g 2525 postfix #新建组postfix
[root@lamp postfix-2.10.10]# useradd -g postfix -u 2525 -M -s /sbin/nologin postfix
#新建用户postfix -g指定所属组,-u指定UID,-M不创建家目录,-s指定登录shell为不可登录nologin.
[root@lamp postfix-2.10.10]# id postfix #查看postfix用户信息
uid=2525(postfix) gid=2525(postfix) 组=2525(postfix)
[root@lamp postfix-2.10.10]# groupadd -g 2526 postdrop #新建组postdrop
[root@lamp postfix-2.10.10]# useradd -g postdrop -u 2526 -M -s /sbin/nologin postdrop
[root@lamp postfix-2.10.10]# id postdrop
uid=2526(postdrop) gid=2526(postdrop) 组=2526(postdrop)
[root@lamp postfix-2.10.10]# yum list all |grep sasl
#查看安装的sasl,确保以下sasl组建已经安装。
This system is not registered with RHN.
RHN support will be disabled.
cyrus-sasl.x86_64 2.1.23-8.el6 @anaconda-RedHatEnterpriseLinux
cyrus-sasl-devel.x86_64 2.1.23-8.el6 @Server
cyrus-sasl-lib.x86_64 2.1.23-8.el6 @anaconda-RedHatEnterpriseLinux
cyrus-sasl-md5.x86_64 2.1.23-8.el6 @anaconda-RedHatEnterpriseLinux
cyrus-sasl-plain.x86_64 2.1.23-8.el6 @anaconda-RedHatEnterpriseLinux
开始执行编译安装:
[root@lamp postfix-2.10.10]# make makefiles 'CCARGS=-DHAS_MySQL -I/usr/local/mysql/include -DUSE_SASL_AUTH -DUSE_CYRUS_SASL -I/usr/include/sasl -DUSE_TLS ''AUXLIBS=-L/usr/local/mysql/lib -lmysqlclient -lz -lm -L/usr/lib64/sasl2 -lsasl2 -lssl -lcrypto'
[root@lamp postfix-2.10.10]# make && make install
#需指定相关的路径,路径可以不用更改,所有的都默认即可。
[root@lamp ~]# postfix start #启动postfix进程
postfix/postfix-script: starting the Postfix mail system
[root@lamp ~]# netstat -tlnp #查看邮件服务25端口是否监听
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 127.0.0.1:631 0.0.0.0:* LISTEN 1553/cupsd
tcp 0 0 0.0.0.0:25 0.0.0.0:* LISTEN 27814/master
tcp 0 0 :::111 :::* LISTEN 1385/rpcbind
tcp 0 0 :::80 :::* LISTEN 2001/httpd
tcp 0 0 :::22 :::* LISTEN 1659/sshd
[root@lamp ~]# tail /var/log/maillog #查看postfix邮件服务日志信息
Feb 28 13:29:01 lamp postfix/postfix-script[27811]: starting the Postfix mail system
Feb 28 13:29:01 lamp postfix/master[27814]: daemon started -- version 2.10.10, configuration /etc/postfix
[root@lamp ~]# telnet localhost 25 #给本机发送邮件
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
220 lamp.com ESMTP Postfix
helo localhost
250 lamp.com
mail from:root #发件人
250 2.1.0 Ok
rcpt to:donggen #收件人
250 2.1.5 Ok
data #邮件正文
354 End data with
Subject:How are you these days? #邮件主题
Are you gua le ma?
. #.结束正文
250 2.0.0 Ok: queued as 01311413
quit #quit退出发送邮件
221 2.0.0 Bye
Connection closed by foreign host.
[root@lamp ~]# tail /var/log/maillog #查看日志文件
Feb 28 14:56:20 lamp postfix/master[28749]: daemon started -- version 2.10.10, configuration /etc/postfix
Feb 28 14:56:44 lamp postfix/smtpd[28763]: warning: dict_nis_init: NIS domain name not set - NIS lookups disabled
Feb 28 14:56:44 lamp postfix/smtpd[28763]: connect from localhost.localdomain[127.0.0.1]
Feb 28 14:57:27 lamp postfix/smtpd[28763]: 01311413: client=localhost.localdomain[127.0.0.1]
Feb 28 14:58:12 lamp postfix/cleanup[28766]: 01311413: message-id=<20170228065727.01311413@lamp.com>
Feb 28 14:58:12 lamp postfix/qmgr[28751]: 01311413: from=
Feb 28 14:58:12 lamp postfix/local[28776]: warning: dict_nis_init: NIS domain name not set - NIS lookups disabled
Feb
28 14:58:12 lamp postfix/local[28776]: 01311413:
to=
Feb 28 14:58:12 lamp postfix/qmgr[28751]: 01311413: removed
Feb 28 14:58:17 lamp postfix/smtpd[28763]: disconnect from localhost.localdomain[127.0.0.1]
[donggen@lamp ~]$ mail #切换使用者,查看邮件。
Heirloom Mail version 12.4 7/29/08. Type ? for help.
"/var/spool/mail/donggen": 1 message 1 new
>N 1 root@lamp.com Tue Feb 28 14:58 14/452 "How are you these days?"
Status: R
Are you OK?
postfix服务启动脚本:可以通过service postfix start|restart
脚本如下:vim /etc/init.d/postfix
1、编辑postfix服务启动脚本
[root@lamp ~]# vim /etc/init.d/postfix
#!/bin/bash
#
#postfix Postfix Mail Transfer Agent
#
#description: Postfix is a Mail Transport Ageent,which is the progrom
# that moves mail from one mochine to another.
#processname:master
#pidfile:/var/spool/postfix/pid/master.pid
#config: /etc/postfix/main.cf
#config: /etc/postfix/master.cf
#Source function library.
. /etc/rc.d/init.d/functions
#Source networking configuretion.
. /etc/sysconfig/network
#Check that networking is up.
[ $NETWORKING = "NO" ] && exit 3
[ -x /usr/sbin/postfix ] || exit 4
[ -d /etc/postfix ] || exit 5
[ -d /var/spool/postfix ] || exit 6
RETVAL=0
prog="postfix"
start() {
# start daemons.
echo -n $"Starting postfix: "
/usr/bin/newaliases >/dev/null 2>&1
/usr/sbin/postfix start 2>/dev/null 1>&2 && success || failure $"$prog start"
RETVAL=$?
[ $RETVAL -eq 0 ] && touch /var/lock/subsys/postfix
echo
return $RETVAL
}
stop() {
# stop daemons.
echo -n $"Shutting down postfix: "
/usr/sbin/postfix stop 2>/dev/null 1>&2 && success || failure $"$prog stop"
RETVAL=$?
[ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/postfix
echo
return $RETVAL
}
reload() {
echo -n $"Reloading postfix: "
/usr/sbin/postfix reload 2>/dev/null 1>&2 && success || failure $"$prog reload"
RETVAL=$?
echo
return $RETVAL
}
abort() {
/usr/sbin/postfix abort 2>/dev/null 1>&2 && success || failure $"$prog abort"
return $?
}
flush() {
/usr/sbin/postfix flush 2>/dev/null 1>&2 && success || failure $"$prog flush"
return $?
}
check() {
/usr/sbin/postfix check 2>/dev/null 1>&2 && success || failure $"$prog check"
return $?
}
restart() {
stop
start
}
# See how we were called.
case "$1" in
start)
start
;;
stop)
stop
;;
restart)
stop
start
;;
reload)
reload
;;
abort)
abort
;;
flush)
flush
;;
check)
check
;;
status)
status master
;;
condrestart)
[ -f /var/lock/subsys/postfix ] && restart || :
;;
*)
echo $"Usage: $0 {start|stop|restart|reload|abort|flush|check|status|condrestart}"
exit 1
;;
esac
exit $?
# END
[root@lamp ~]# chmod +x /etc/init.d/postfix
[root@lamp ~]# chkconfig --add postfix #把postfix添加至开机启动
[root@lamp ~]# chkconfig --list postfix #查看postfix开机是否自动启动
[root@lamp ~]# service postfix restart
关闭 postfix: [确定]
启动 postfix: [确定]
2、进行一些基本配置,测试启动postfix并进行发信。
修改/etc/postfix/main.cf
修改以下几项配置(红色部分):
myhostname = mail.lamp.com
myorigin =
mydomain =
mydestination =
mynetworks =
说明:
myorigin参数用来指明发件人所在的域名,即做发件地址伪装;
myhostname参数指定运行postfix邮件系统的主机的主机名,默认情况下,其值被设定为本地机器名;
mydomain参数指定自己的域名,默认情况下postfix将myhostname的第一部分删除而作为mydomain的值;
mydestination参数指定postfix接收邮件时收件人的域名,即你的postfix系统要接受到那个域名的邮件
mynetworks参数指定你所在的网络的网络地址,postfix系统根据其值来区别用户是远程的还是本地的,
如果是本地网络用户则允许其访问;
inet_interfaces参数指定postfix系统监听的网络接口;
注意:
1、在postfix的配置文件中,参数行和注释行是不能处在同一行中的;
2、任何一个参数的值都不需要加引号,否则,引号将会被当做参数值的一部分来使用;
3、每修改参数及其值后执行postfix reload即可令其生效,但若修改了inet_interfaces;
则需重新启动postfix;
4、如果一个参数的值有多个,可以将他们放在不同的行中,只需要在其后的每个行前多置一个空格
即可;postfix会把第一个字符为空格或tab的文本行视为上一行的延续;
3、修改主机名
[root@lamp ~]# hostname mail.lamp.com #临时修改主机名,立即生效,重启失效
[root@lamp ~]# hostname
mail.lamp.com
[root@lamp ~]# vim /etc/sysconfig/network #永久生效,修改主机名,重启后生效
NETWORKING=yes
HOSTNAME=mail.lamp.com
[root@mail ~]# hostname
mail.lamp.com
4、安装配置DNS服务器
[root@mail ~]# rpm -qa |grep bind #查看系统是否安装过DNS
PackageKit-device-rebind-0.5.8-13.el6.x86_64
bind-libs-9.7.0-5.P2.el6.x86_64
samba-winbind-clients-3.5.4-68.el6.x86_64
bind-utils-9.7.0-5.P2.el6.x86_64
rpcbind-0.2.0-8.el6.x86_64
[root@mail ~]# rpm -e bind-libs bind-utils #先卸载已经安装的bind
[root@mail ~]# yum install bind.x86_64 bind-libs bind-utils
Loaded plugins: refresh-packagekit, rhnplugin
This system is not registered with RHN.
RHN support will be disabled.
Setting up Install Process
Resolving Dependencies
--> Running transaction check
---> Package bind.x86_64 32:9.7.0-5.P2.el6 set to be updated
---> Package bind-libs.x86_64 32:9.7.0-5.P2.el6 set to be updated
---> Package bind-utils.x86_64 32:9.7.0-5.P2.el6 set to be updated
--> Finished Dependency Resolution
Dependencies Resolved
=====================================================================================================
Install 3 Package(s)
Upgrade 0 Package(s)
Total download size: 4.4 M
Installed size: 8.9 M
Is this ok [y/N]: y
Downloading Packages:
-----------------------------------------------------------------------------------------------------
Total 80 MB/s | 4.4 MB 00:00
Complete! #安装完成
[root@mail ~]# vim /etc/named.conf #编辑DNS配置文件
[root@mail ~]# service named start #启动DNS服务
启动 named: [确定]
[root@mail ~]# netstat -tlnp #查看监听的端口
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 0.0.0.0:56201 0.0.0.0:* LISTEN 1450/rpc.statd
tcp 0 0 0.0.0.0:3306 0.0.0.0:* LISTEN 1958/mysqld
tcp 0 0 10.109.134.237:53 0.0.0.0:* LISTEN 7794/named
tcp 0 0 127.0.0.1:53 0.0.0.0:* LISTEN 7794/named
tcp 0 0 192.168.122.1:53 0.0.0.0:* LISTEN 2229/dnsmasq
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 1659/sshd
tcp 0 0 127.0.0.1:953 0.0.0.0:* LISTEN 7794/named
tcp 0 0 0.0.0.0:25 0.0.0.0:* LISTEN 6341/master
[root@mail ~]# vim /etc/named.rfc1912.zones #编辑正向和反向代理设置,
在最末尾增加以下内容:
zone "lamp.com" IN {
type master;
file "lamp.com.zone";
allow-update { none; };
allow-transfer { none; };
};
zone "134.109.10.in-addr.arpa" IN {
type master;
file "10.109.134.zone";
allow-update { none; };
allow-transfer { none; };
};
[root@mail ~]# named-checkconf #检查dns配置文件是否有语法错误
[root@mail ~]# named-checkconf /etc/named.conf #指定检查那个DNS配置文件是否有语法错误
[root@mail ~]# cd /var/named/
[root@mail named]# vim lamp.com.zone #编辑正向代理文件,内容如下;
[root@mail named]# vim 10.109.134.zone #编辑反向代理文件,内容如下;
[root@mail named]# chgrp named lamp.com.zone 10.109.134.zone #更改组为named
[root@mail named]#chmod 640 10.109.134.zone lamp.com.zone #修改权限为640
[root@mail named]# ll
总用量 36
-rw-r-----. 1 root named 285 3月 1 11:46 10.109.134.zone
drwxrwx---. 2 named named 4096 3月 1 11:01 data
drwxrwx---. 2 named named 4096 3月 1 11:02 dynamic
-rw-r-----. 1 root named 292 3月 1 11:43 lamp.com.zone
-rw-r-----. 1 root named 1892 2月 18 2008 named.ca
-rw-r-----. 1 root named 152 12月 15 2009 named.empty
-rw-r-----. 1 root named 152 6月 21 2007 named.localhost
-rw-r-----. 1 root named 168 12月 15 2009 named.loopback
drwxrwx---. 2 named named 4096 5月 26 2010 slaves
[root@mail named]# named-checkzone "lamp.com" lamp.com.zone #检查正向代理文件是否正确
zone lamp.com/IN: loaded serial 2017030101
OK
[root@mail named]# named-checkzone "134.109.10.in-addr.arpa" 10.109.134.zone #检查反向代理配置文件是否正确
zone 134.109.10.in-addr.arpa/IN: loaded serial 2017030101
OK
[root@mail named]# service named restart #重启named服务
停止 named: [确定]
启动 named: [确定]
[root@mail named]# chkconfig named on #加入到开机启动列表
[root@mail named]# dig -t MX lamp.com @10.109.134.237 #测试解析MX记录是否正常
; <<>> DiG 9.7.0-P2-RedHat-9.7.0-5.P2.el6 <<>> -t MX lamp.com @10.109.134.237
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 46065
;; flags: qr aa rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 1, ADDITIONAL: 2
;; QUESTION SECTION:
;lamp.com.INMX
;; ANSWER SECTION:
lamp.com.600INMX10 mail.lamp.com.
;; AUTHORITY SECTION:
lamp.com.600INNSns.lamp.com.
;; ADDITIONAL SECTION:
mail.lamp.com.600INA10.109.134.237
ns.lamp.com.600INA10.109.134.237
;; Query time: 0 msec
;; SERVER: 10.109.134.237#53(10.109.134.237)
;; WHEN: Wed Mar 1 13:39:05 2017
;; MSG SIZE rcvd: 96
[root@mail named]# dig -t A mail.lamp.com @10.109.134.237 #测试邮件A记录解析是否正常
; <<>> DiG 9.7.0-P2-RedHat-9.7.0-5.P2.el6 <<>> -t A mail.lamp.com @10.109.134.237
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 46985
;; flags: qr aa rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 1, ADDITIONAL: 1
;; QUESTION SECTION:
;mail.lamp.com.INA
;; ANSWER SECTION:
mail.lamp.com.600INA10.109.134.237
;; AUTHORITY SECTION:
lamp.com.600INNSns.lamp.com.
;; ADDITIONAL SECTION:
ns.lamp.com.600INA10.109.134.237
;; Query time: 0 msec
;; SERVER: 10.109.134.237#53(10.109.134.237)
;; WHEN: Wed Mar 1 13:46:39 2017
;; MSG SIZE rcvd: 80
[root@mail named]# cd /etc/postfix
[root@mail postfix]# vim main.cf #编辑postfix邮箱服务主配置文件,内容如下;
[root@mail postfix]# service postfix restart
关闭 postfix: [确定]
启动 postfix: [确定]
[root@mail postfix]# vim /etc/resolv.conf #编辑DNS配置
[root@mail postfix]# telnet mail.lamp.com 25
Trying 10.109.134.237...
Connected to mail.lamp.com.
Escape character is '^]'.
220 mail.lamp.com ESMTP Postfix
helo mail.lamp.com
250 mail.lamp.com
mail from:test@test.com
250 2.1.0 Ok
rcpt to:admin@xuelinux.com
250 2.1.5 Ok
data
354 End data with
hello
.
250 2.0.0 Ok: queued as 2623AE31
quit
221 2.0.0 Bye
Connection closed by foreign host.
postfix2.10下载地址:
ftp://ftp.cuhk.edu.hk/pub/packages/mail-server/postfix/index.html
我们在微信上24小时期待你的声音
解答本文疑问/技术咨询/运营咨询/技术建议/互联网交流