FreeBSD下架构Postfix的邮件系统


该附言或许不成其为什么许可证,但还是希望您尊重作者的愿望。
如果您发现有什么错误,请及时通知我,我将尽快作出修改。如果您在网上转载,那将是免费,但希望您附上本附言,并且注明出处的链接。如果您要把它用印刷物形式出版,请通过www.cnfug.org,或通过我的个人网站www.e-era.net跟本人接洽。
您在以本文作为根据配置电脑的时候,若出现任何故障,后果自负,与本作者无关。

Chapter 0. 准备数据库

详见mail.e-era.net.sql

Chapter 1. 安装相关软件

1.1 安装 cyrus-sasl2-saslauthd
mail# cd /usr/ports/security/cyrus-sasl2
下载加密口令认证补丁,否则只能明码认证
mail# fetch http://www.viperstrike.com/~lopaka/sysadmin/cyrus-sasl-mysql-encrypt/software-sources/patch
mail# mv patch files/patch-lib::chkpw.c
mail# make -DWITH_PGSQL -DWITH_DEV_URANDOM -DWITHOUT_OTP -DWITHOUT_CRAM -DWITHOUT_DIGEST -DWITHOUT_NTLM install clean
mail# cd /usr/ports/security/cyrus-sasl2-saslauthd
mail# make install clean
mail# ln -s /usr/local/lib/sasl2 /usr/lib/sasl2

1.2 安装 postfix 和 cyrus-sasl
mail# cd /usr/ports/mail/postfix
mail# make install clean
选择下面的内容:
[X] SASL2
[X] TLS
[X] PGSQL
回答下面的两问题:
You need user "postfix" added to group "mail".
Would you like me to add it [y]? y

Would you like to activate Postfix in /etc/mail/mailer.conf [n]? n

mail# cd /usr/local/etc/rc.d
mail# ln -s /usr/local/sbin/sendmail /usr/sbin/sendmail
如果/usr/sbin/sendmail存在就删了再做上链接
mail# echo ‘postfix: root’ >> /etc/aliases
mail# /usr/local/bin/newaliases
mail# chown postfix:postfix /etc/opiekeys

1.3 安装expect
用于Web客户端建立邮件用户
mail# cd /usr/ports/lang/expect
mail# make install clean

1.4 安装Courier-imap
mail# cd /usr/ports/mail/courier-authlib
mail# make install clean
选择
[X] POSTGRESQL
[X] AUTHUSERDB

mail# cd /usr/ports/mail/courier-imap
mail# make WITHOUT_OPENSSL=yes WITH_PGSQL=yes install clean
选择
[X] OPENSSL
[X] IPV6

mail# cd /usr/local/etc/courier-imap
mail# cp imapd.cnf.dist imapd.cnf
mail# cp pop3d.cnf.dist pop3d.cnf

Chapter 2. 配置邮件服务器

2.1 配置rc.conf,编辑/etc/rc.conf,加入
saslauthd_enable="YES"
sendmail_enable="YES"
sendmail_flags="-bd"
sendmail_pidfile="/var/spool/postfix/pid/master.pid"
sendmail_outbound_enable="NO"
sendmail_submit_enable="NO"
sendmail_msp_queue_enable="NO"
courier_authdaemond_enable="YES"
courier_imap_pop3d_enable="YES"
courier_imap_imapd_enable="YES"

2.2 配置cyrus-sasl2-saslauthd
(1)配置sasl的lib库
在/etc/defaults/rc.conf文件里的ldconfig_paths="/usr/local/lib后面加上/usr/local/lib/sasl2"

(2)创建/usr/lib/sasl2/Sendmail.conf 示例:Sendmail.conf

(3)建立smtpd.conf连接
mail# ln -s /usr/lib/sasl2/Sendmail.conf /usr/lib/sasl2/smtpd.conf

(4)编辑/usr/local/etc/rc.d/saslauthd.sh
command="${prefix}/sbin/${name} -r"

2.3 配置postfix 和 cyrus-sasl
(1)创建/etc/periodic.conf
daily_clean_hoststat_enable="NO"
daily_status_mail_rejects_enable="NO"
daily_status_include_submit_mailq="NO"
daily_submit_queuerun="NO"

(2)修改/usr/local/etc/postfix/main.cf,在文件最后加入以下内容
#======= BASE ==============
myhostname = mail.hzpc.cn
mydomain = hzpc.cn
home_mailbox = Maildir/
mydestination = $myhostname, $mydomain, $transport_maps
local_recipient_maps =
mailbox_command= /usr/local/bin/deliverquota -w 90 ~/Maildir
command_directory = /usr/local/sbin

#======= PGSQL =============
transport_maps = pgsql:/usr/local/etc/postfix/transport.cf
virtual_gid_maps = pgsql:/usr/local/etc/postfix/gids.cf
virtual_mailbox_base = /var/mail
virtual_mailbox_maps = pgsql:/usr/local/etc/postfix/pgsql_virtual.cf
virtual_maps = pgsql:/usr/local/etc/postfix/pgsql.aliases.cf
virtual_uid_maps = pgsql:/usr/local/etc/postfix/uids.cf

#======= Quota ============
message_size_limit = 5242880 //限制每次发邮件的大小5MB(请将此注解删除)
virtual_mailbox_limit_inbox = no
virtual_mailbox_limit_maps = pgsql:/usr/local/etc/postfix/mailboxsize-pgsql.cf
virtual_mailbox_limit_override = yes
virtual_maildir_extended = yes
virtual_create_maildirsize = yes
virtual_mailbox_limit = 52428800 //总邮箱的大小50MB(请将此注解删除)

#====== 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

(3)确认/usr/local/etc/postfix/master.cf的配置有如下内容
virtual unix - n n - - virtual

(4)编辑/usr/local/etc/postfix/transport.cf 示例:transport.cf

(5)编辑/usr/local/etc/postfix/gids.cf 示例:gids.cf

(6)编辑/usr/local/etc/postfix/uids.cf 示例:uids.cf

(7)编辑/usr/local/etc/postfix/pgsql_virtual.cf 示例:pgsql_virtual.cf

(8)编辑/usr/local/etc/postfix/pgsql.aliases.cf 示例:pgsql.aliases.cf

(9)编辑/usr/local/etc/postfix/mailboxsize-pgsql.cf 示例:mailboxsize-pgsql.cf

2.4 配置Courier-imap
(1)修改/usr/local/etc/courier-imap/imapd
IMAP_CAPABILITY="IMAP4rev1 CHILDREN NAMESPACE THREAD=ORDEREDSUBJECT THREAD=REFERENCES SORT AUTH=LOGIN AUTH=PLAIN AUTH=CRAM-MD5 AUTH=CRAM-SHA1 IDLE"
IMAP_CAPABILITY_ORIG="IMAP4rev1 UIDPLUS CHILDREN NAMESPACE THREAD=ORDEREDSUBJECT THREAD=REFERENCES SORT QUOTA AUTH=LOGIN AUTH=PLAIN AUTH=CRAM-MD5 AUTH=CRAM-SHA1 AUTH=CRAM-SHA256 IDLE"
IMAPDSTART=YES

(2)修改/usr/local/etc/courier-imap/imapd-ssl
IMAPDSSLSTART=NO
IMAPDSTARTTLS=NO
POP3DSTART=YES

(3)修改/usr/local/etc/courier-imap/pop3d
POP3AUTH="LOGIN CRAM-MD5 CRAM-SHA1"
POP3AUTH_ORIG="LOGIN CRAM-MD5 CRAM-SHA1 CRAM-SHA256"

(4)修改/usr/local/etc/courier-imap/pop3d-ssl
POP3DSSLSTART=NO
POP3_STARTTLS=NO

(5)编辑修改/usr/local/etc/authlib/authpgsqlrc 示例:authmysqlrc

(4)编辑/usr/local/etc/authlib/authdaemonrc
authmodulelist="authpgsql authpam authuserdb"
authmodulelistorig="authpgsql authpam authuserdb"
version="authdaemond.pgsql"

重启服务器

(5)接着检查端口,应该有如下端口打开:
mail# netstat -an |grep LISTEN
tcp4 0 0 *.110 *.* LISTEN
tcp6 0 0 *.110 *.* LISTEN
tcp4 0 0 *.143 *.* LISTEN
tcp6 0 0 *.143 *.* LISTEN
tcp4 0 0 *.25 *.* LISTEN

Chapter 3. 设置域、用户并测试

3.0 准备Crypt密码
#======== crypt.php ========#
if (isset( FreeBSD下架构Postfix的邮件系统 - 站长学院


Copyright © 2016 phpStudy |