利用Ubuntu ExtMail 30分钟配置好一个功能强大的邮件

2010-05-21

利用Ubuntu ExtMail 30分钟配置好一个功能强大的邮件服务器V1.1,以下文档通过19个大的步骤进行配置,配置成功! 

由于网上Ubuntu ExtMail的步骤特别多,看了都头痛,在此特别给朋友们制作了一个简洁的安装文档,希望大家喜欢:)

环境:
Ubuntu         8.04 TLS
postfix        2.5.1
ExtMail       1.2
extman        1.1 

1.安装依赖包
apt-get install mysql-client-5.0 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 liblzo1 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

 

你会被询问以下问题:
Create directories for web-based administration? <– No
General type of mail configuration: <– Internet Site
System mail name: <– mail.extmail.org

 

2.下载extmail-1.2和extman-1.1,并修改配置
下载地址:http://www.extmail.org/download
tar xvzf extmail-1.2.tar.gz
tar xvzf extman-1.1.tar.gz
mkdir /var/www/extsuite
mv extmail-1.2/ /var/www/extsuite/extmail
mv extman-1.1/ /var/www/extsuite/extman
cp /var/www/extsuite/extman/docs/mysql_virtual_*.cf /etc/postfix/

注意,非常重要:修改/etc/postfix/mysql_virtual_*.cf,将其中的“localhost”均改为“127.0.0.1”,修改数据库配置,保证能够连到mysql

 

3.建立相关系统用户
1)新建普通用户
useradd -m -d /home/hugwww -s /bin/bash hugwww
passwd hugwww

2)删除以前gid,uid为1000的用户
userdel -r gaojinbo

3)建立extmail所需要的用户和组
groupadd -g 1000 vgroup
useradd -m -g vgroup -u 1000 -d /home/vmail -s /bin/false vuser

 

4.修改权限
chmod 755 /etc/postfix/mysql_virtual_*.cf
chgrp postfix /etc/postfix/mysql_virtual_*.cf
chown -R vuser:vgroup /var/www/extsuite/extmail/cgi/
chown -R vuser:vgroup /var/www/extsuite/extman/cgi/
cd /var/www/extsuite/extmail/
cp webmail.cf.default webmail.cf
cd /var/www/extsuite/extman/
cp webman.cf.default webman.cf

 

5.修改/var/www/extsuite/extmail/webmail.cf里的其他参数,主要变动的内容见下:
vi /var/www/extsuite/extmail/webmail.cf

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 = 102400000 //注:这个选项为修改附件的大小,默认为5M,你可以自行修改,这里面改了是不行的,还要去postfix里面修改,我在下面会讲到

 

6.修改 /var/www/extsuite/extman/webman.cf的参数
vi /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] //注:这个选项是,你在后台群发后,用户收到邮件的发件人地址,你可以自行修改

 

7.修改/var/www/extsuite/extman/contrib/passwd2ext.pl

my $sock = ‘/var/run/mysqld/mysqld.sock’;

 

 

9.建立临时文件夹:
mkdir /tmp/extman
chown -R vuser:vgroup /tmp/extman

if [ ! -d /tmp/extman ]; then
mkdir /tmp/extman
chown -R vuser:vgroup /tmp/extman

fi 

10.建立上边导入mysql的[email protected]帐户的Maildir,请输入如下命令:
cd /var/www/extsuite/extman/tools
./maildirmake.pl /home/vmail/extmail.org/postmaster/Maildir
chown -R vuser:vgroup /home/vmail/extmail.org/

 

11.Postfix配置
cd /etc/postfix/
cp main.cf main.cf_backup

vi main.cf
# TLS parameters
smtpd_tls_cert_file = /etc/postfix/smtpd.cert
smtpd_tls_key_file = /etc/postfix/smtpd.key
smtpd_use_tls = yes
# See /usr/share/doc/postfix/TLS_README.gz in the postfix-doc package for
# information on enabling SSL in the smtp client.
mydomain = extmail.org
myhostname = mail.$mydomain
myorigin = $mydomain
mydestination = mail.$mydomain, localhost.$mydomain, localhost
alias_maps = hash:/etc/aliases
alias_database = hash:/etc/aliases
relayhost =
mynetworks = 127.0.0.1
message_size_limit = 102400000
mailbox_size_limit = 0
recipient_delimiter = +
inet_interfaces = all
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 mailbox try again.
proxy_read_maps = $local_recipient_maps $mydestination $virtual_alias_maps $virtual_alias_domains $virtual_mailbox_maps $virtual_mailbox_domains $relay_recipient_maps $relay_domains $canonical_maps $sender_canonical_maps $recipient_canonical_maps $relocated_maps $transport_maps $mynetworks $virtual_mailbox_limit_maps

重启 postfix
/etc/init.d/postfix restart

 

12.SMTP身份认证
cd /etc/postfix
openssl req -new -outform PEM -out smtpd.cert -newkey rsa:2048 -nodes -keyout smtpd.key -keyform PEM -days 365 -x509

 

 

14.编辑/var/www/extsuite/extmail/dispatch-init文件:
vi  /var/www/extsuite/extmail/dispatch-init
MAXFORK=10
最后启动fastcgi server:
/var/www/extsuite/extmail/dispatch-init start
如果没有意外将启动10个dispatch.fcgi守护进程,可以通过以下命令将启动命令加到rc.local中,实现自启动:
echo "/var/www/extsuite/extmail/dispatch-init start">>/etc/rc.local

 

15.SMTP认证
1).更改saslauthd
vi /etc/default/saslauthd
更改如下几项
START=yes    //设置开机自动启动
OPTIONS="-c -m /var/spool/postfix/var/run/saslauthd -r"

2). 创建文件/etc/pam.d/smtp
vi /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表示加密或者不加密  注意对照你的数据库还有用户名密码 请保持跟自己的一致

3).由于postfix处于chroot,要想调用到saslauthd 必须更改socket文件
mkdir -p /var/spool/postfix/var/run/saslauthd
vi /etc/postfix/sasl/smtpd.conf

创建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’

4).更改main.cf 文件
vi  /etc/postfix/main.cf
###########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_recipient_restrictions = permit_mynetworks, permit_sasl_authenticated, reject_sender_login_mismatch, 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_pipelining, reject_invalid_hostname, check_recipient_maps

5).添加用户
adduser postfix sasl

6).重启postfix saslauthd
/etc/init.d/postfix restart
/etc/init.d/saslauthd restart

7).测验
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 表示没有问题了

 

16.POP验证
vi /etc/courier/authdaemonrc
#更改如下一项
authmodulelist="authmysql"

cp /etc/courier/authmysqlrc /etc/courier/authmysqlrc_orig
cat /dev/null > /etc/courier/authmysqlrc

vi /etc/courier/authmysqlrc
#内容如下:
MYSQL_SERVER            localhost
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         uidnumber
MYSQL_GID_FIELD         gidnumber
MYSQL_LOGIN_FIELD       username
MYSQL_HOME_FIELD        homedir
MYSQL_NAME_FIELD        name
MYSQL_MAILDIR_FIELD     maildir
MYSQL_QUOTA_FIELD       quota
MYSQL_SELECT_CLAUSE     SELECT username,password,"",uidnumber,gidnumber,\
                        CONCAT(‘/home/vmail/’,homedir),               \
                        CONCAT(‘/home/vmail/’,maildir),               \
                        quota,                                          \
                        name,                                           \
                        CONCAT("disablesmtpd=",disablesmtpd,            \
                        ",disablesmtp=",disablesmtp,                    \
                        ",disablewebmail=",disablewebmail,              \
                        ",disablenetdisk=",disablenetdisk,              \
                        ",disableimap=",disableimap,                    \
                        ",disablepop3=",disablepop3,                    \
                        ",netdiskquota=",netdiskquota)                  \
                        FROM mailbox                                    \
                        WHERE username = ‘$(local_part)@$(domain)’

配置Courier-POP3
vi /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
测试pop3
telnet localhost 110
Trying 127.0.0.1…
Connected to localhost.localdomain (127.0.0.1).
Escape character is ‘^]’.
+OK Hello there.
user [email protected]
+OK Password required.
pass extmail
+OK logged in.
list
+OK POP3 clients that break here, they violate STD53.
.
quit
+OK Bye-bye.
Connection closed by foreign host.
如果出现问题请仔细分析日志

 

17.图形日志extmail
apt-get install mailgraph
cp -r /var/www/extsuite/extman/addon/mailgraph_ext/ /usr/local/mailgraph_ext

vi /usr/local/mailgraph_ext/mailgraph-init为:
MAIL_LOG=/var/log/mail.log
然后复制文件
cp /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

 

18.安装Maildrop
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 vuser vgroup
sharedscripts
}

vi /etc/postfix/master.cf,注释掉原来maildrop的配置内容并改为:
maildrop   unix  -       n        n       -       -        pipe
   flags=DRhu  user=vmail argv=maildrop -w 90 -d ${user}@${nexthop} ${recipient} ${user}  ${extension} {nexthop}

由于maildrop不支持一次接收多个收件人,因此必须在/etc/postfix/main.cf增加如下参数:
vi /etc/postfix/main.cf
###### Maildrop config ########
maildrop_destination_recipient_limit = 1
virtual_transport = maildrop:

创建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.

 

19.解决extman问题
1)修改相关服务路径
vi /var/www/extsuite/extman/daemon/cmd_plugin/linux-cmd

2)启动服务
/var/www/extsuite/extman/daemon/cmdserver -v -d

3)写入rc.local开机自动运行
echo "/var/www/extsuite/extman/daemon/cmdserver -v -d" >>/etc/rc.local

相关推荐