postfix
# tar xf /postfix.tar.gz -C /usr/local/src
# vim /etc/yum.repos.d/local.repo
[base]
name=base
baseurl=file:///mnt/cdrom/Server
enabled=1
gpgcheck=0
[postfix]
name=postfix
baseurl=file:///usr/local/src/postfix
enabled=1
gpgcheck=0
# yum clean all
# yum list
1 安装postfix
安装postfix,版本一定要postfix-2.6.2-5版本
# yum install postfix -y
# rpm -qa |grep postfix
postfix-2.6.2-5hzq
停掉sendmail
# /etc/init.d/sendmail stop
# chkconfig sendmail off
# chkconfig --list sendmail
切换默认mta
# alternatives --config mta
There are 2 programs which provide 'mta'.
Selection Command
-----------------------------------------------
*+ 1 /usr/sbin/sendmail.sendmail
2 /usr/sbin/sendmail.postfix
Enter to keep the current selection[+], or type selection number: 2
开机自动启动postfix
# chkconfig postfix on
修改主机名
# hostname mail.extmail.org
# vim /etc/sysconfig/network
HOSTNAME=mail.extmail.org
# vim /etc/hosts
127.0.0.1 mail.extmail.org mail localhost.localdomain localhost
::1 localhost6.localdomain6 localhost6
192.168.3.5 mail.extmail.org
-------------------------------
生成postfix的默认配置文件
# postconf -n > /etc/postfix/main.cf
# vim /etc/postfix/main.cf
config_directory = /etc/postfix
#hostname
mynetworks = 127.0.0.1
myhostname = mail.extmail.org
mydomain = extmail.org
mydestination = $mynetworks $myhostname
#banner
mail_name = Postfix -uplooking
smtpd_banner = $myhostname ESMTP $mail_name
#response immediately
smtpd_error_sleep_time = 0s
#message and return code control
message_size_limit = 5242880
mailbox_size_limit = 52428800
show_user_unknown_table_name = no
#queue lifetime control
bounce_queue_lifetime = 1d
maximal_queue_lifetime = 1d
# /etc/init.d/postfix start
Starting postfix:
# netstat -altunp |grep :25
tcp 0 0 0.0.0.0:25 0.0.0.0:* LISTEN 6985/master
实验邮件服务是否可用
# telnet mail.extmail.org 25
Trying 127.0.0.1...
Connected to localhost.localdomain (127.0.0.1).
Escape character is '^]'.
220 mail.extmail.org ESMTP Postfix -uplooking
ehlo mail.extmail.org
250-mail.extmail.org
250-PIPELINING
250-SIZE 5242880
250-VRFY
250-ETRN
250-ENHANCEDSTATUSCODES
250-8BITMIME
250 DSN
mail from: root@mail.extmail.org //发信方邮件地址
250 2.1.0 Ok
rcpt to: tom@mail.extmail.org //对方邮件地址
250 2.1.5 Ok
data //开始写内容
354 End data with <CR><LF>.<CR><LF>
subject: hello mike //邮件标题
hello tom
this is john
.
250 2.0.0 Ok: queued as 61FBAE8031
quit
2 postfix 认证功能
# yum install expect libtool-lib
# yum install courier-authlib courier-authlib-mysql courier-authlib-devel
# cd /etc/authlib
# vim /etc/authlib/authmysqlrc
26 MYSQL_SERVER localhost
27 MYSQL_USERNAME extmail
28 MYSQL_PASSWORD extmail
49 MYSQL_SOCKET /var/lib/mysql/mysql.sock
56 MYSQL_PORT 3306
62 MYSQL_OPT 0
68 MYSQL_DATABASE extmail
83 MYSQL_USER_TABLE mailbox
92 MYSQL_CRYPT_PWFIELD password
113 MYSQL_UID_FIELD uidnumber
119 MYSQL_GID_FIELD gidnumber
128 MYSQL_LOGIN_FIELD username
133 MYSQL_HOME_FIELD homedir
139 MYSQL_NAME_FIELD name
150 MYSQL_MAILDIR_FIELD maildir
165 MYSQL_QUOTA_FIELD quota
289 MYSQL_SELECT_CLAUSE SELECT username,password,"",uidnumber,gidnumber,\
290 CONCAT('/home/domains/',homedir), \
291 CONCAT('/home/domains/',maildir), \
292 quota, \
293 name \
294 FROM mailbox \
295 WHERE username = '$(local_part)@$(domain)'
安装mysql-server
# yum install mysql-server -y
# /etc/init.d/mysqld start
# chkconfig mysqld on
# 告诉你的MRA只使用mysql作为信息验证数据库
# vim /etc/authlib/authdaemonrc
27 authmodulelist="authmysql"
34 authmodulelistorig="authmysql"
# /etc/init.d/courier-authlib start
Starting Courier authentication services: authdaemond
# chkconfig courier-authlib on
# chmod 755 /var/spool/authdaemon
安装maildrop , 用于MDA
# yum install maildrop -y
# vim /etc/postfix/master.cf
63 maildrop unix - n n - - pipe
64 flags=DRhu user=vuser argv=maildrop -w 90 -d ${user}@${nexthop} $ {recipient} ${user} ${extension} {nexthop}
# vim /etc/postfix/main.cf
maildrop_destination_recipient_limit = 1
postfix 服务重启
# /etc/init.d/postfix restart
# maildrop -v
maildrop 2.0.4 Copyright 1998-2005 Double Precision, Inc.
GDBM extensions enabled.
Courier Authentication Library extension enabled. //一定要看到这一行
Maildir quota extension enabled.
This program is distributed under the terms of the GNU General Public
License. See COPYING for additional information.
安装apache
# yum install httpd -y
# vim /etc/httpd/conf/httpd.conf
# vim /etc/httpd/conf.d/vhost_extmail.conf
安装extmail
# yum install extsuite-webmail
# cd /var/www/extsuite/extmail/
# cp webmail.cf.default webmail.cf
# vim webmail.cf
136 SYS_MYSQL_USER = extmail
137 SYS_MYSQL_PASS = extmail
138 SYS_MYSQL_DB = extmail
139 SYS_MYSQL_HOST = localhost
140 SYS_MYSQL_SOCKET = /var/lib/mysql/mysql.sock
# chown -R vuser:vgroup /var/www/extsuite/extmail/cgi/
安装extman 后台管理界面
# yum install extsuite-webman
# chown -R vuser:vgroup /var/www/extsuite/extman/cgi/
# mkdir /tmp/extman
# chown vuser:vgroup /tmp/extman
-----------------------
导入extmail 数据库
# cd /var/www/extsuite/extman/docs
# mysql -u root < extmail.sql
# mysql -u root < init.sql
# pwd
/var/www/extsuite/extman/docs
[root@mail docs]# cp mysql_virtual_alias_maps.cf /etc/postfix/
[root@mail docs]# cp mysql_virtual_domains_maps.cf /etc/postfix/
[root@mail docs]# cp mysql_virtual_mailbox_maps.cf /etc/postfix/
[root@mail docs]# cp mysql_virtual_sender_maps.cf /etc/postfix/
# vim /etc/postfix/main.cf
virtual_alias_maps = mysql:/etc/postfix/mysql_virtual_alias_maps.cf
virtual_mailbox_maps = mysql:/etc/postfix/mysql_virtual_mailbox_maps.cf
virtual_mailbox_domains = mysql:/etc/postfix/mysql_virtual_domains_maps.cf
virtual_transport = maildrop:
# /etc/init.d/postfix restart
测试 authlib
# /usr/sbin/authtest -s login postmaster@extmail.org extmail
Authentication FAILED: Input/output error
如果出现错误 Input/output error
基本上是 /etc/authlib/mysqlrc 文件语句错误
# vim /etc/authlib/authdaemonrc
DEBUG_LOGIN=1
# /etc/init.d/courier-authlib restart
# /etc/init.d/postfix restart
重新运行 # /usr/sbin/authtest -s login postmaster@extmail.org extmail
查看日志 /var/log/maillog 就能找到相应的错误提示
# vim /etc/authlib/authmysqlrc
[root@mail var]# /usr/sbin/authtest -s login postmaster@extmail.org extmail
Authentication succeeded.
Authenticated: postmaster@extmail.org (uid 1000, gid 1000)
Home Directory: /home/domains/extmail.org/postmaster
Maildir: /home/domains/extmail.org/postmaster/Maildir/
Quota: 104857600S
Encrypted Password: $1$phz1mRrj$3ok6BjeaoJYWDBsEPZb5C0
Cleartext Password: extmail
Options: (none)
# /etc/init.d/httpd restart
# firefox http://mail.extmail.org/extmail/ &
# firefox http://mail.extmail.org/extmail/ &
默认超级用户 root@extmail.org 密码 extmail*123*
配置图形化日志
启动 mailgraph_ext
# /usr/local/mailgraph_ext/mailgraph-init start
Starting mail statistics grapher: mailgraph_ext
Starting queue statistics grapher: qmonitor
启动 cmdserver(后台显示系统信息)
# /var/www/extsuite/extman/daemon/cmdserver --daemon
loaded ok
开机自动启动
# echo "/usr/local/mailgraph_ext/mailgraph-init start" >> /etc/rc.local
# echo "/var/www/extsuite/extman/daemon/cmdserver --daemon" >> /etc/rc.local
-------------------
安装 cyrus-sasl 使postfix支持认证
# yum install cyrus-sasl-sql -y
# vim /etc/postfix/main.cf
smtpd_recipient_restrictions = #针对收件人的限制
permit_mynetworks,
permit_sasl_authenticated,
reject_non_fqdn_hostname,
reject_non_fqdn_sender,
reject_non_fqdn_recipient,
reject_unauth_destination,
reject_unauth_pipelining,
reject_invalid_hostname
#smtpd sender login matching config
smtpd_sender_restrictions = #针对发信人的限制
permit_mynetworks,
reject_sender_login_mismatch,
reject_authenticated_sender_login_mismatch,
reject_unauthenticated_sender_login_mismatch
smtpd_sender_login_maps =
mysql:/etc/postfix/mysql_virtual_sender_maps.cf
mysql:/etc/postfix/mysql_virtual_alias_maps.cf
#smtp auth config
broken_sasl_auth_clients = yes
smtpd_sasl_auth_enable = yes
smtpd_sasl_local_domain = $myhostname
smtpd_sasl_security_options = noanonymous
# vim /usr/lib/sasl2/smtpd.conf
pwcheck_method: authdaemond
log_level: 3
mech_list: PLAIN LOGIN
authdaemond_path:/var/spool/authdaemon/socket
# /etc/init.d/saslauthd restart
# /etc/init.d/postfix restart
SMTP验证
# perl -e 'use MIME::Base64; print encode_base64("postmaster\@extmail.org")'
cG9zdG1hc3RlckBleHRtYWlsLm9yZw==
# perl -e 'use MIME::Base64; print encode_base64("extmail")'ZXh0bWFpbA==
# telnet mail.extmail.org 25
Trying 127.0.0.1...
Connected to localhost.localdomain (127.0.0.1).
Escape character is '^]'.
220 mail.extmail.org ESMTP Postfix -uplooking
ehlo mail.extmail.org //手动输入
250-mail.extmail.org
250-PIPELINING
250-SIZE 5242880
250-VRFY
250-ETRN
250-AUTH PLAIN LOGIN
250-AUTH=PLAIN LOGIN
250-ENHANCEDSTATUSCODES
250-8BITMIME
250 DSN
auth login
334 VXNlcm5hbWU6
cG9zdG1hc3RlckBleHRtYWlsLm9yZw==
334 UGFzc3dvcmQ6
ZXh0bWFpbA==
235 2.7.0 Authentication successful
------------------------
安装 courier-imap 收邮件工具 MRA
# yum install courier-imap -y
# vim /usr/lib/courier-imap/etc/imapd
414 IMAPDSTART=NO
# vim /usr/lib/courier-imap/etc/imapd-ssl
75 IMAPDSSLSTART=NO
# /etc/init.d/courier-imap restart
# telnet mail.extmail.org 110
Trying 127.0.0.1...
Connected to localhost.localdomain (127.0.0.1).
Escape character is '^]'.
+OK Hello there.
user john@extmail.org //手动输入
+OK Password required.
pass john //手动输入
+OK logged in.
quit
+OK Bye-bye.
# firefox http://mail.extmail.org/extman
添加几个用户,添加域名
# firefox http://mail.extmail.org/extmail
互相写信, 看看能否收到邮件
转载于:https://blog.51cto.com/plking/1330450