apt-get install mysql-client-5.1 mysql-server apache2 postfix postfix-mysql postfix-doc courier-authdaemon courier-authlib-mysql courier-pop courier-pop-ssl courier-imap courier-imap-ssl libsasl2-modules libsasl2-modules-sql sasl2-bin libpam-mysql openssl libapache2-mod-fastcgi libfcgi-perl build-essential libtool libnet-server-perl libnet-cidr-perl libberkeleydb-perl arc zoo lzop liblzo2-dev libstdc++5 libgd-gd2-perl libfile-tail-perl libdigest-sha1-perl libdigest-HMAC-perl libnet-ip-perl libnet-dns-perl libhtml-tagset-perl libhtml-parser-perl libio-stringy-perl libio-multiplex-perl libio-socket-ssl-perl libio-zlib-perl libnet-ssleay-perl libunix-syslog-perl libtimedate-perl libmailtools-perl libconvert-binhex-perl libconvert-tnef-perl libconvert-uulib-perl libcompress-zlib-perl libarchive-zip-perl libarchive-tar-perl perl-suid
cp /var/www/extsuite/extman/docs/mysql_virtual_*.cf /etc/postfix/
useradd -m -d /home/www -s /bin/bash www passwd www以上新建用户的uid和pid都是1001,可以修改passwd文件和group文件进行替换。
SYS_USER_LANG = zh_CN # 语言设置 SYS_MYSQL_USER = extmail # 默认访问数据库的用户名 SYS_MYSQL_PASS = extmail # 默认访问数据库的密码 SYS_MYSQL_DB = extmail # 默认访问数据库的名字 SYS_MYSQL_SOCKET = /var/run/mysqld/mysqld.sock SYS_AUTHLIB_SOCKET = /var/run/courier/authdaemon/socket SYS_MAILDIR_BASE = /home/vmail SYS_MESSAGE_SIZE_LIMIT = 102400000vim /var/www/extsuite/extman/webman.cf
SYS_CAPTCHA_ON = 0 ##用于关闭后台登录时的验证码 SYS_MAILDIR_BASE = /home/vmail SYS_MYSQL_SOCKET = /var/run/mysqld/mysqld.sock SYS_LANG = zh_CN SYS_GROUPMAIL_SENDER = [email protected]vim /var/www/extsuite/extman/contrib/passwd2ext.pl
my $sock = '/var/run/mysqld/mysqld.sock';
mysql -u root -pgaojinbo.com < /var/www/extsuite/extman/docs/extmail.sql mysql -u root -pgaojinbo.com < /var/www/extsuite/extman/docs/init.sql临时文件夹建立
mkdir /tmp/extman chown -R www:www /tmp/extman初始化[email protected]帐户的Maildir文件夹
cd /var/www/extsuite/extman/tools ./maildirmake.pl /home/vmail/extmail.org/postmaster/Maildir chown -R www:www /home/vmail/extmail.org/
# See /usr/share/postfix/main.cf.dist for a commented, more complete version # Debian specific: Specifying a file name will cause the first # line of that file to be used as the name. The Debian default # is /etc/mailname. #myorigin = /etc/mailname smtpd_banner = $myhostname ESMTP $mail_name (Ubuntu) biff = no # appending .domain is the MUA's job. append_dot_mydomain = no # Uncomment the next line to generate "delayed mail" warnings #delay_warning_time = 4h readme_directory = /usr/share/doc/postfix # TLS parameters smtpd_tls_cert_file=/etc/ssl/certs/ssl-cert-snakeoil.pem smtpd_tls_key_file=/etc/ssl/private/ssl-cert-snakeoil.key smtpd_use_tls=no smtpd_tls_session_cache_database = btree:${data_directory}/smtpd_scache smtp_tls_session_cache_database = btree:${data_directory}/smtp_scache # See /usr/share/doc/postfix/TLS_README.gz in the postfix-doc package for # information on enabling SSL in the smtp client. mydomain = 1k8k.com myhostname = mail.1k8k.com alias_maps = hash:/etc/aliases alias_database = hash:/etc/aliases myorigin = /etc/mailname mydestination = 127.0.0.1,mail.1k8k.com relayhost = mynetworks = 127.0.0.1 mailbox_size_limit = 0 recipient_delimiter = + inet_interfaces = loopback-only html_directory = /usr/share/doc/postfix/html ######### virtual config############ virtual_alias_domains = virtual_alias_maps = mysql:/etc/postfix/mysql_virtual_alias_maps.cf virtual_mailbox_domains = mysql:/etc/postfix/mysql_virtual_domains_maps.cf virtual_mailbox_maps = mysql:/etc/postfix/mysql_virtual_mailbox_maps.cf virtual_mailbox_limit_maps = mysql:/etc/postfix/mysql_virtual_limit_maps.cf virtual_mailbox_base = /home/vmail virtual_uid_maps = static:1000 virtual_gid_maps = static:1000 virtual_create_maildirsize = yes virtual_mailbox_extended = yes virtual_overquota_bounce = yes virtual_mailbox_limit_override = yes virtual_maildir_limit_message = Sorry, the your Maildir has overdrawn your diskspace quota, please free up some of spaces of your ma ilbox try again. proxy_read_maps = $local_recipient_maps $mydestination $virtual_alias_maps $virtual_alias_domains $virtual_mailbox_maps $virtual_mai lbox_domains $relay_recipient_maps $relay_domains $canonical_maps $sender_canonical_maps $recipient_canonical_maps $relocated_maps $ transport_maps $mynetworks $virtual_mailbox_limit_maps ###########SMTP AUTH config############### broken_sasl_auth_clients = yes smtpd_sasl_auth_enable = yes #smtpd_sasl_local_domain = $myhostname smtpd_sasl_security_options = noanonymous ###########smtpd related config############ smtpd_client_restrictions = permit_sasl_authenticated smtpd_recipient_restrictions = permit_mynetworks, permit_sasl_authenticated, reject_unauth_destination #smtpd_recipient_restrictions = permit_mynetworks, permit_sasl_authenticated, reject_unknown_sender_domain, reject_non_fqdn_hostname , reject_non_fqdn_sender, reject_non_fqdn_recipient, reject_unknown_recipient_domain, reject_unauth_destination, reject_unauth_pipel ining, reject_invalid_hostname, check_recipient_maps ###### Maildrop config ######## maildrop_destination_recipient_limit = 1 virtual_transport = maildrop:重启postfix,检查是否有语法错误
/etc/init.d/postfix restart
cd /etc/postfix openssl req -new -outform PEM -out smtpd.cert -newkey rsa:2048 -nodes -keyout smtpd.key -keyform PEM -days 365 -x509
<VirtualHost *> ServerAdmin [email protected] ServerName mail.1k8k.com DocumentRoot /var/www/extsuite/extmail/html Alias /extmail/cgi/ /var/www/extsuite/extmail/dispatch.fcgi/ Alias /extmail /var/www/extsuite/extmail/html <Ifmodule mod_fastcgi.c> FastCgiExternalServer /var/www/extsuite/extmail/dispatch.fcgi -host 127.0.0.1:8888 -idle-timeout 240 </Ifmodule> <Location "/extmail/cgi"> SetHandler fastcgi-script </Location> ScriptAlias /extman/cgi/ /var/www/extsuite/extman/cgi/ Alias /extman /var/www/extsuite/extman/html ErrorLog /var/log/apache2/error.log # Possible values include: debug, info, notice, warn, error, crit, # alert, emerg. LogLevel warn CustomLog /var/log/apache2/access.log combined SuexecUserGroup vuser vgroup </VirtualHost>
START=yes //设置开机自动启动 OPTIONS="-c -m /var/spool/postfix/var/run/saslauthd -r"创建文件/etc/pam.d/smtp 内容如下:
auth required pam_mysql.so user=extmail passwd=extmail host=127.0.0.1 db=extmail table=mailbox usercolumn=username passwdcolumn=password crypt=1 account sufficient pam_mysql.so user=extmail passwd=extmail host=127.0.0.1 db=extmail table=mailbox usercolumn=username passwdcolumn=password crypt=1解释一下:其实就是定义一个查询的方式 crypt=1或者0表示加密或者不加密 注意对照你的数据库 还有用户名密码 请保持跟自己的一致 由于postfix处于chroot,要想调用到saslauthd 必须更改socket文件
mkdir -p /var/spool/postfix/var/run/saslauthd创建smtpd.conf,并且内容如下:
pwcheck_method:saslauthd mech_list:plain login allow_plaintext: true auxprop_plugin: mysql sql_hostnames: 127.0.0.1 sql_user: extmail sql_password: extmail sql_database: extmail log_level:7 sql_select: SELECT password FROM mailbox WHERE username='%u@%r' and domain='%r'修改的内容已经在前面添加进去,SMTP AUTH config和smtpd related config两个部分的配置文件
telnet localhost 25 Trying 127.0.0.1… Connected to localhost. Escape character is ‘^]’. 220 mail.extmail.org ESMTP Postfix ehlo localhost # 输入内容 250-mail.extmail.org 250-PIPELINING 250-SIZE 102400000 250-VRFY 250-ETRN 250-STARTTLS 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 # 显示认证成功 quit 221 2.0.0 Bye Connection closed by foreign host.如果出现Authentication successful 表示成功咯
authmodulelist="authmysql"cp /etc/courier/authmysqlrc /etc/courier/authmysqlrc_orig cat /dev/null > /etc/courier/authmysqlrc vim /etc/courier/authmysqlrc
DEFAULT_DOMAIN 1k8k.com MYSQL_SERVER 127.0.0.1 MYSQL_USERNAME extmail MYSQL_PASSWORD extmail MYSQL_SOCKET /var/run/mysqld/mysqld.sock MYSQL_PORT 3306 MYSQL_OPT 0 MYSQL_DATABASE extmail MYSQL_USER_TABLE mailbox MYSQL_CRYPT_PWFIELD password MYSQL_UID_FIELD 104 MYSQL_GID_FIELD 112 MYSQL_LOGIN_FIELD username MYSQL_HOME_FIELD /home/vmail MYSQL_NAME_FIELD name MYSQL_MAILDIR_FIELD /home/vmail MYSQL_QUOTA_FIELD quota MYSQL_SELECT_CLAUSE SELECT username,password,domain, uidnumber,gidnumber, CONCAT('/home/vmail/',homedir), CONCAT('/home/vmail/',maildir), quota, name FROM mailbox WHERE username = '$(local_part)@$(domain)' AND active = 1
vim /etc/courier/pop3d MAILDIRPATH=/home/vmail配置Courier-IMAP
vi /etc/courier/imapd MAILDIRPATH=/home/vmail/重启服务
/etc/init.d/courier-authdaemon restart /etc/init.d/courier-imap restart /etc/init.d/courier-imap-ssl restart /etc/init.d/courier-pop restart /etc/init.d/courier-pop-ssl restart测试Courier- Authlib是否能成功连接mysql
authtest -s login [email protected] extmail如果成功会显示如下:
Authentication succeeded. Authenticated: [email protected] (uid 1000, gid 1000) Home Directory: /home/vmail/extmail.org/postmaster Maildir: /home/vmail/extmail.org/postmaster/Maildir/ Quota: 104857600S Encrypted Password: $1$phz1mRrj$3ok6BjeaoJYWDBsEPZb5C0 Cleartext Password: extmail Options: disablesmtpd=0,disablesmtp=0,disablewebmail=0,disablenetdisk=0, disableimap=0,disablepop3=0,netdiskquota=52428800S
MAIL_LOG=/var/log/mail.logcp /var/www/extsuite/extman/addon/mailgraph_ext/mailgraph-init /etc/init.d/mailgraph cp /var/www/extsuite/extman/addon/mailgraph_ext/qmonitor.pl /etc/init.d/qmonitor 启动服务
/etc/init.d/mailgraph start
apt-get install maildrop
vi /etc/maildropmysql.config //创建一个文件
hostname localhost port 3306 database extmail dbuser extmail dbpw extmail dbtable mailbox default_uidnumber 1000 default_gidnumber 1000 uidnumber_field uidnumber gidnumber_field gidnumber uid_field username homedirectory_field concat('/home/vmail/',homedir,'/') maildir_field concat('/home/vmail/',maildir) quota_field quota mailstatus_field active
修改/etc/maildroprc
vi /etc/maildroprc
logfile "/var/log/maildrop.log"
vi /var/log/maildrop.log
chown vuser:vgroup /var/log/maildrop.log chmod 766 /var/log/maildrop.log
vi /etc/logrotate.d/maildrop
/var/log/maildrop.log { daily notifempty missingok rotate 5 compress create 766 www www sharedscripts }
vi /etc/postfix/master.cf,注释掉原来maildrop的配置内容并改为:
maildrop unix - n n - - pipe flags=DRhu user=www argv=maildrop -w 90 -d ${user}@${nexthop} ${recipient} ${user} ${extension} {nexthop} #flags前面必须空2格
由于maildrop不支持一次接收多个收件人,因此必须在/etc/postfix/main.cf增加参数,已经在前面main.cnf里面添加,就是Maildrop config里面的配置
创建vi /etc/quotawarnmsg,为邮箱空间超过配额时的警告邮件内容:
X-Comment: Rename/Copy this file to quotawarnmsg, and make appropriate changes X-Comment: See deliverquota man page for more information From: Mail Delivery System <[email protected]> Reply-To: [email protected] To: Valued Customer:; Subject: Mail quota warning Mime-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: 7bit Your mailbox on the server is now more than 90% full. So that you can continue to receive mail you need to remove some messages from your mailbox.
/var/www/extsuite/extman/daemon/cmdserver -v -d
echo "/var/www/extsuite/extman/daemon/cmdserver -v -d" >>/etc/rc.local
登录http://mail.1k8k.com/extmail/ 前台,http://mail.1k8k.com/extman/后台
后台默认用户名 [email protected] 默认密码 extmail*123*,登录前台需要自己先添加一个用户