基本Postfix安装+配置

因为Blog和下载系统需要个邮件通知系统,Ramhost的CentOS模板是光板 - 不仅没有sendmail,连mta都没设置。在几个MTA中间比较来比较去最后选了postfix,看中其安全性和可扩展性。

因为我就需要个SMTP,没打算做成Webmail系统,因此有这方面需求的同学请出门右转。

平台是CentOS 5.5,不清楚Debian的怎么做。

首先安装源码编译必须要的包:

yum install db4-devel

我的系统上就差这么个包,请参考自己服务器情况决定。

然后tar解包进去make,暂时不make install - 还有些东西要设置。

首先添加用户:

useradd postfix

然后在/etc/passwd里面把shell改成/sbin/nologin,home改成/dev/null,密码域改成星号。

再建立postdrop组:

groupadd postdrop

然后就可以make install了。注意postfix的源码安装一直没有uninstall这个选项,装上去了要想删的话就得手工删。

所有路径全部采用默认。

装好了修改/etc/postfix/main.cf,修改如下选项:

找到myhostname = host.domain.tld,改为myhostname = mail.myhost,以自己的域名为准。

找到#mydomain = domain.tld,改为mydomain = myhost

取消如下行前的注释:

myorigin = $mydomain
inet_interfaces = localhost
mydestination = $myhostname, localhost.$mydomain, localhost, $mydomain
relay_domains = $mydestination
home_mailbox = Maildir/

修改SMTP banner避免探测:

smtpd_banner = $myhostname ESMTP unknown

因为只接受本地连接所以没必要加ESMTP了。

然后设置系统MTA:

一般来说用alternatives --config mta选择postfix就可以了,但是因为我的系统没默认mta所以:

alternatives --install /usr/sbin/sendmail mta /usr/sbin/sendmail 25

然后写postfix的init script:

#
# postfix This shell script takes care of starting and stopping
# postfix.
#
# chkconfig: 2345 80 30
#
# description: Postfix is a Mail Transport Agent, which is the program
# that moves mail from one machine to another.
# Source function library.
. /etc/rc.d/init.d/functions

# Source networking configuration.
. /etc/sysconfig/network

# Check that networking is up.
[${NETWORKING} = "no"] && exit 0

[-f /usr/sbin/postfix] || exit 0

# See how we were called.
case "$1" in
 start)
 	# Start daemons.
 	echo -n "Starting postfix: "
 	newaliases
 	for I in access canonical relocated transport virtual
 	do
 		if [-f /etc/postfix/$I] ; then
 			/usr/sbin/postmap hash:/etc/postfix/$I < /etc/postfix/$I
 		fi
 	done
 	/usr/sbin/postfix start 2>/dev/null
 	echo postfix
 	touch /var/lock/subsys/postfix
 ;;
 stop)
 	# Stop daemons.
 	echo -n "Shutting down postfix: "
 	/usr/sbin/postfix stop 2>/dev/null
 	echo postfix
 	rm -f /var/lock/subsys/postfix
;;
 restart)
	 $0 stop
 	$0 start
 ;;
 reload)
	 /usr/sbin/postfix reload
 	;;
 status)
 	status master
 ;;
 \*)
 echo "Usage: $0 {start|stop|restart|reload|status}"
 exit 1
 esac

exit 0

chmod 755 /etc/init.d/postfix,然后chkconfig postfix on让postfix自动启动。

/etc/init.d/postfix start启动postfix,然后telnet 127.0.0.1 25试试发封信,看看能不能发出去。

简单的测试命令:

HELO myhost
MAIL FROM:admin@myhost
RCPT TO:xxx@xxx.xxx
DATA

结束data的方法是按回车,输入句点再按回车,就是.


.

QUIT

检查目的邮箱应该有信了 - 当然也有很大可能在junk mail里面。

然后php.ini里面可能也要设置一下sendmail路径:

sendmail\_path = /usr/sbin/sendmail -t -i

搞定。用php试试发封信看看?

本文参考了以下资料:

http://wiki.zimbra.com/wiki/How_to_%22fix%22_system%27s_sendmail_to_use_that_of_zimbra

http://www.centospub.com/make/postfix_smtp.html

标签:

更新时间: