Postfix邮件系统安装手册
8.安装postfix
1)停止sendmail
hawk# mv /usr/bin/newaliases /usr/bin/newaliases.OFF
hawk# mv /usr/bin/mailq /usr/bin/mailq.OFF
hawk# mv /usr/sbin/sendmail /usr/sbin/sendmail.OFF
hawk# mv /etc/rc.sendmail /etc/sendmail.OFF
hawk# edit /etc/rc.conf(在sendmail="YES"前面添加# )
2)添加postfix用户
hawk# pw groupadd postfix -g 2003
hawk# pw groupadd postdrop -g 2004
hawk# pw useradd postfix -u 2003 -g 2003 -d /dev/null -s /nologin
3)安装 postfix 2.1.13
为了让系统可以支持 Quota 下载 Quota 补丁
http://web.onda.com.br/nadal/
为了让系统支持TLS
ftp ftp://ftp.aet.tu-cottbus.de/pub/postfix_tls/pfixtls-0.8.18-2.1.3-0.9.7d.tar.gz
./pfixtls-0.8.18-2.1.3-0.9.7d/contributed/make-postfix-cert.sh
Apply the TLS patch to the Postfix source per README file contained in pfixtls* package:
patch -p0 < pfixtls-0.8.16-2.0.15-0.9.7b/pfixtls.diff
hawk# tar zxvf postfix-2.1.13.tar.gz
hawk# cd postfix-2.1.13
make -f Makefile.init makefiles ''CCARGS=-DUSE_SASL_AUTH -DHAS_MYSQL
-DHAS_SSL -I/usr/local/include/openssl -I/usr/local/include/mysql -I/usr/local/include/sasl'' ''AUXLIBS=-L/usr/local/lib/ -L/usr/local/lib/mysql
-lmysqlclient -lssl -lcrypto -lsasl2 -lz -lm''
hawk# make
hawk# make install(第一次安装使用此命令,安装过程中如果提示错误则在提示选择tmp的时候使用/tmp)
hawk# make upgrade(升级老版本使用此命令)
4)配置
hawk# echo ‘postfix: root’ >> /etc/aliases
hawk# /usr/bin/newaliases
(注:如果提示postfix无法打开opiekeys文件则执行:#hawk chown postfix:postfix /etc/opiekeys)
A)编辑修改/etc/posftix/main.cf 示例:main.cf
#======= BASE ==============
myhostname = mail.elm.com
mydomain = elm.com
home_mailbox=Maildir/
mydestination = $myhostname,$transport_maps
local_recipient_maps =
mailbox_command= /usr/lib/courier-imap/bin/deliverquota -w 90 ~/Maildir
content_filter = smtp-amavis:[127.0.0.1]:10024
#======= MYSQL =============
transport_maps = mysql:/etc/postfix/transport.cf
virtual_gid_maps = mysql:/etc/postfix/gids.cf
virtual_mailbox_base = /var/mail
virtual_mailbox_maps = mysql:/etc/postfix/mysql_virtual.cf
virtual_maps = mysql:/etc/postfix/mysql.aliases.cf
virtual_uid_maps = mysql:/etc/postfix/uids.cf
#======= Quota ============
message_size_limit = 2097152
virtual_mailbox_limit_inbox = yes
virtual_mailbox_limit_maps = mysql:/etc/postfix/mailboxsize-mysql.cf
virtual_mailbox_limit_override = yes
virtual_maildir_extended = yes
virtual_create_maildirsize = yes
virtual_mailbox_limit = 10485760
#====== SASL ================
smtpd_sasl_auth_enable = yes
smtpd_sasl_security_options = noanonymous
broken_sasl_auth_clients = yes
smtpd_recipient_restrictions = permit_sasl_authenticated,permit_auth_destination
,reject
#smtpd_sasl_local_domain = $mydomain
smtpd_client_restrictions = permit_sasl_authenticated
# tls config
smtp_use_tls = yes
smtpd_use_tls = yes
smtp_tls_note_starttls_offer = yes
smtpd_tls_key_file = /etc/postfix/ssl/smtpd.pem
smtpd_tls_cert_file = /etc/postfix/ssl/smtpd.pem
smtpd_tls_CAfile = /etc/postfix/ssl/smtpd.pem
smtpd_tls_loglevel = 1
smtpd_tls_received_header = yes
smtpd_tls_session_cache_timeout = 3600s
tls_random_source = dev:/dev/urandom
# end TLS
readme_directory = no
sample_directory = /etc/postfix
sendmail_path = /usr/sbin/sendmail
html_directory = no
setgid_group = postdrop
command_directory = /usr/sbin
manpage_directory = /usr/local/man
daemon_directory = /usr/libexec/postfix
newaliases_path = /usr/bin/newaliases
mailq_path = /usr/bin/mailq
queue_directory = /var/spool/postfix
mail_owner = postfix
B)确认/etc/postfix/master.cf的配置有如下内容
virtual unix - n n - - virtual
C)编辑/etc/posftix/transport.cf
示例:transport.cf
user = postfix
password = hawk
dbname = mail
table = transport
select_field = transport
where_field = domain
hosts = localhost
D)编辑/etc/postfix/gids.cf
示例:gids.cf
user = postfix
password= hawk
dbname = mail
table = virtual_users
select_field = gid
where_field = id
hosts = localhost
E)编辑/etc/postfix/uids.cf
示例:uids.cf
user = postfix
password= hawk
dbname = mail
table = virtual_users
select_field = uid
where_field = id
hosts = localhost
F)编辑/etc/posftix/mysql_virtual.cf
示例:mysql_virtual.cf
user = postfix
password= hawk
dbname = mail
table = virtual_users
select_field = maildir
where_field = id
hosts = localhost
G)编辑/etc/postfix/mysql.aliases.cf 示例:mysql.aliases.cf
user = postfix
password= hawk
dbname = mail
table = aliases
select_field = rcpt
where_field = alias
hosts = localhost
H)编辑/etc/postfix/mailboxsize-mysql.cf 示例:mailboxsize-mysql.cf
user = postfix
password = hawk
dbname = mail
table = virtual_users
select_field = quota
where_field = id
hosts = localhost
5)设置自启动
hawk# edit /usr/local/etc/rc.d/postfix-server.sh
示例:postfix-server.sh
#!/bin/sh
case "$1" in
start)
if [ -x /usr/sbin/postfix ]; then
/usr/sbin/postfix start && echo -n '' postfix''
fi
;;
stop)
/usr/sbin/postfix stop && echo -n '' postfix''
;;
*)
echo ""
echo "Usage: `basename $0` { start | stop }"
echo ""
exit 64
;;
esac
hawk# chmod 755 /usr/local/etc/rc.d/postfix-server.sh
9.安装expect.tar.gz(need tcl)
hawk# pkg_add tcl-8.3.5_2.tgz
hawk# tar zxvf expect-5.38.tar.gz
hawk# cd expect-5.38
hawk# ./configure --enable-threads --with-tcl=/usr/local/lib/tcl8.3 --with-tclinclude=/usr/local/include/tcl8.3
hawk# make
hawk# make install