Ubuntu下安装postfix+extmail邮件服务器

系统:ubuntu-10.04.3-server-amd64

安装LAMP环境

sudo apt-get install apache2

sudo apt-get install mysql-server-5.0 mysql-client-5.0

sudo apt-get install php5 libapache2-mod-php5

sudo /etc/init.d/apache2 restart


接下来修改apache2的配置文件。

sudo vim /etc/apache2/apache2.conf


把下面的代码全部考到文件的最后。

AddType application/x-httpd-php .php .htm .html
AddDefaultCharset UTF-8
ServerName 127.0.0.1
<IfModule dir_module>
DirectoryIndex index.htm index.html index.php
</IfModule>

重新启动

/etc/init.d/apache2 restart

/etc/init.d/mysql restart



apt-get install liblzo2-2


apt-get install libstdc++6-4.4-dev

apt-get install postfix postfix-mysql postfix-doc mysql-client mysql-server 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 phpmyadmin apache2 libapache2-mod-fastcgi libfcgi-perl libapache2-mod-php5 php5 php5-mysql build-essential libtool libnet-server-perl libnet-cidr-perl libberkeleydb-perl arc zoo lzop 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 perl-suid apache2-suexec



你会被询问以下问题:

Create directories for web-based administration? <-- No

General type of mail configuration: <-- Internet Site

System mail name: <-- mail.extmail.org(直接改成要用的域名:mail.object.com 待测试)


a2enmod suexec //打开apache2 suexec支持

a2enmod fastcgi //打开apache2 fastcgi支持

sudo /etc/init.d/apache2 restart



Extmail 是一个以perl语言编写,面向大容量/ISP级应用,免费的高性能Webmail软件,主要包括ExtMail、  Extman两个部分的程序套件。ExtMail套件用于提供从浏览器中登录、使用邮件系统的Web操作界面,而Extman套件用于提供从浏览器中管理邮件系统的Web操作界面。

下载extmail,并修改配置

我用的是ExtMail 1.1.0.tar.gz和ExtMan 1.0.0.tar.gz

tar zxvf extmail-1.1.0.tar.gz

tar zxvf extman-1.0.0.tar.gz

mkdir /var/www/extsuite

mv extmail-1.1.0 /var/www/extsuite/extmail

mv extman-1.0.0 /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”

(:g/a/s//b/g将文中所有a均用b替换(或者:%s/a/b/g)

Sudo sed �Ci ‘/localhost/s/localhost/127.0.0.1/’ file*)

chmod o= /etc/postfix/mysql_virtual_*.cf

chgrp postfix /etc/postfix/mysql_virtual_*.cf


注:如果打算使用默认用户vuser:vgroup,那么需创建此用户,且uid:gid为1001:1001.而本文为了以后方便,使用的是手动创建的用户vmail,所以需修改下边这些文件中的相关参数.

新建一个用户vmail组为vmail uid和gid为1001,不允放登录。用户下用来存放所有的用户的邮件

groupadd -g 1001 vmail

useradd -m -g vmail -u 1001 -d /home/vmail -s /bin/bash vmail

id vmail


注:如果打算使用默认用户vu修改uid和gid 由于程序中默认使用的为vuser:vgroup,其uid:gid为1001:1001。而当前采用了一个新建用户vmail,所以需修改程序中的所有相关参数,具体操作如下:

chown -R vmail:vmail /var/www/extsuite/extmail/cgi/

chown -R vmail:vmail /var/www/extsuite/extman/cgi/


cd /var/www/extsuite/extmail/

cp webmail.cf.default webmail.cf

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

gedit webmail.cf

SYS_USER_LANG = zh_CN
SYS_USER_CHARSET = gb2312
SYS_MYSQL_USER = root
SYS_MYSQL_PASS = 123
SYS_MYSQL_DB = extmail
SYS_MYSQL_HOST = 127.0.0.1
SYS_MYSQL_SOCKET = /var/run/mysqld/mysqld.sock
SYS_AUTHLIB_SOCKET = /var/run/courier/authdaemon/socket
SYS_G_ABOOK_FILE_CHARSET = gb2312
SYS_MAILDIR_BASE = /home/vmail
SYS_MESSAGE_SIZE_LIMIT = 102400000 //注:这个选项为修改附件的大小,默认为5M,你可以自行修改,这里面改了是不行的,还要去postfix里面修改,我在下面会讲到。


vi ../extman/webman.cf

cp webman.cf.default webman.cf

vi webman.cf



SYS_CAPTCHA_ON = 0 //用于关闭后台登录时的验证码
SYS_MAILDIR_BASE = /home/vmail
SYS_DEFAULT_UID = 1001
SYS_DEFAULT_GID = 1001
SYS_MYSQL_USER = root
SYS_MYSQL_PASS = 123
SYS_MYSQL_DB = extmail
SYS_MYSQL_HOST = 127.0.0.1
SYS_MYSQL_SOCKET = /var/run/mysqld/mysqld.sock
SYS_LANG = zh_CN
SYS_GROUPMAIL_SENDER = [email protected] //注: 这个选项是,你在后台群发后,用户收到邮件的发件人地址,你可以自行修改。




Cd ..

Cd  extmail



gedit dispatch-init

SU_UID=vmail

SU_GID=vmail


gedit dispatch_lig.sh

BASE=/var/www/extsuite/extmail

$BASE/tools/suid-with -u vmail -g vmail /usr/bin/perl $BASE/dispatch.fcgi

:q

cd ../extman/

gedit tools/setid.pl

set_gid('vmail');

set_uid('vmail');


gedit tools/adminctl.pl

--setgid=vmail

--setuid=vmail


gedit tools/userctl.pl

--setgid=vmail

--setuid=vmail


gedit tools/aliasctl.pl

--setgid=vmail

--setuid=vmail


gedit tools/domainctl.pl

--setgid=vmail

--setuid=vmail


注:这上面实际上都是把vuser改成vmail,vgroup改成vmail.


gedit contrib/passwd2ext.pl

my $sock = '/var/run/mysqld/mysqld.sock';

my $uid = '1001';

my $gid = '1001';


gedit libs/Ext/Mgr/LDAP.pm

uidNumber => $opt{uidnumber} || '1001', //349行

gidNumber => $opt{gidnumber} || '1001', //350行

�U

uidNumber => $opt{uidnumber} || '1001', //541行

gidNumber => $opt{gidnumber} || '1001', //542行


gedit docs/init.ldif

uidNumber: 1001

gidNumber: 1001


gedit /var/www/extsuite/extman/docs/init.sql

修改18行中的uid和gid

INSERT INTO `mailbox` VALUES ('[email protected]','postmaster','$1$phz1mRrj$3ok6BjeaoJYWDBsEPZb5C0','','PostMaster','','extmail.org/postmaster/Maildir/','extmail.org/postmaster','104857600S','52428800S','extmail.org',1001,1001,'2007-02-14 15:10:04','2010-11-08',1,0,0,0,0,0,0,0,'my question', 'my answer');


gedit /var/www/extsuite/extman/docs/extmail.sql

修改uid和gid

CREATE TABLE mailbox (

�U

�U

129行 uidnumber int(6) NOT NULL default '1001',

130行 gidnumber int(6) NOT NULL default '1001',

�U)

到此,vmail用户组修改完毕。





数据库初始化

执行以下命令导入mysql数据库结构及初始化数据,注意必须逐行输入以下命令.

mysql -u root -p < /var/www/extsuite/extman/docs/extmail.sql

mysql -u root -p < /var/www/extsuite/extman/docs/init.sql


链接基本库到Extmail

建立临时文件夹:

mkdir /tmp/extman

chown -R vmail:vmail /tmp/extman


gedit /etc/rc.local

编辑rc.local,加入下面内容以实现开机自动建立编辑rc.local,加入下面内容以实现开机自动建立


if [ ! -d /tmp/extman ]; then

mkdir /tmp/extman

chown -R vmail:vmail /tmp/extman

fi



注:linux系统有个tmpwatch工具,该工具会定期扫描/tmp/下的文件,如果这些文件很久都没被使用,将被删除,因此如果后台长期不使用, /tmp/extman目录有可能被tmpwatch删除,所以要么定期登陆后台,要么修改 webman.cf将临时目录修改到另一个地方。此处暂以/tmp/extman默认值为例。

(如果/tmp下没有extman目录,后台登陆不了,会报错)


建立上边导入mysql的[email protected]帐户的Maildir,请输入如下命令:

cd /var/www/extsuite/extman/tools

./maildirmake.pl /home/vmail/extmail.org/postmaster/Maildir

chown -R vmail:vmail /home/vmail/extmail.org/


Postfix配置

修改/etc/postfix/mysql_virtual_*.cf,将其中的localhost均改为127.0.0.1



cd /etc/postfix/

cp main.cf main.cf_backup

gedit main.cf


删除所有,添加下列文件


# TLS parameters
smtpd_tls_cert_file = /etc/postfix/smtpd.cert
smtpd_tls_key_file = /etc/postfix/smtpd.key
smtpd_use_tls = yes
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 = 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:1001
virtual_gid_maps = static:1001
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

把上面的都复制到你的main.cf文件中,各位可以按自己的要求自行配置



代码:

cd /etc/postfix

openssl req -new -outform PEM -out smtpd.cert -newkey rsa:2048 -nodes -keyout smtpd.key -keyform PEM -days 365 -x509

它们询问你问题

Country Name (2 letter code) [AU]: //国家

State or Province Name (full name) [Some-State]: //省

Locality Name (eg, city) []: //城市

Organization Name (eg, company) [Internet Widgits Pty Ltd]: //组织名称

Organizational Unit Name (eg, section) []: 组织单位名称

Common Name (eg, YOUR name) []: 通用名称

Email Address []: 邮件地址

更改smtpd.key权限

chmod o= /etc/postfix/smtpd.key


/etc/init.d/postfix restart



接下来是Apache2配置:

我们可以新建一个站点,如果你的服务器,只是做邮件服务器,你可以直接修改默认的配置文件,不过修改前,还是要备份一下。

我到sites-available下新建了一个extmail的文件件,里面的代码是这样(参考)

<VirtualHost *:80>
ServerAdmin [email protected]
ServerName mail.test.com
DocumentRoot /var/www/extsuite/extmail/html/
ScriptAlias /extmail/cgi/ /var/www/extsuite/extmail/cgi/
Alias /extmail /var/www/extsuite/extmail/html/
ScriptAlias /extman/cgi/ /var/www/extsuite/extman/cgi/
Alias /extman/ /var/www/extsuite/extman/html/
Alias /phpmyadmin /var/www/extsuite/phpmyadmin/
ErrorLog /var/log/apache2/extmail-error.log
CustomLog /var/log/apache2/extmail-access.log combined
</VirtualHost>


接下来我们加载站点


a2ensite extmail

/etc/init.d/apache2 restart



你还要修改apache2里的配置文件

gedit /etc/apache2/apache2.conf


User vmail

Group vmail


添加apache2的启动用户 user vmail group vmail

你还要去执行这两条命令,不然apache2启动不起来的

chmod 777 /var/lib/apache2/fastcgi

chmod 777 /var/lib/apache2/fastcgi/dynamic

sudo /etc/init.d/apache2 restart

编辑/var/www/extsuite/extmail/dispatch-init文件:

MAXFORK=10

最后启动fastcgi server:

sudo /var/www/extsuite/extmail/dispatch-init start




如果没有意外将启动10个dispatch.fcgi守护进程,可以通过以下命令将启动命令加到rc.local中,实现自启动:

echo "/var/www/extsuite/extmail/dispatch-init start" >> /etc/rc.local



/etc/init.d/apache2 restart



访问页面

在客户端(XP)测试

添加hosts文件

192.168.10.67  mail.test.com浏览器访问

http://mail.test.com/extman/cgi/index.cgi

进入后台管理

添加域名

域列表--添加域   添加邮箱所要使用的域。

mail.test.com

后台用户名:[email protected] 密码:extmail*123*


现在我们来做SMTP认证

1.更改saslauthd




代码:

gedit /etc/default/saslauthd


更改如下几项:



代码:

START=yes 设置开机自动启动
OPTIONS="-c -m /var/spool/postfix/var/run/saslauthd -r"



2. 创建文件/etc/pam.d/smtp

内容如下:




代码:

auth required pam_mysql.so user=root passwd=123456 host=127.0.0.1 db=extmail table=mailbox usercolumn=username passwdcolumn=password crypt=1
account sufficient pam_mysql.so user=root passwd=123456 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

gedit /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: root   //数据库用户名
sql_password: 123456  //数据库密码
sql_database: extmail
log_level:7
sql_select: SELECT password FROM mailbox WHERE username='%u@%r' and domain='%r'


4.更改main.cf 文件




代码:

gedit /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



加入以上的内容


添加用户




代码:

adduser postfix sasl



5.重启postfix saslauthd




代码:

/etc/init.d/postfix restart

/etc/init.d/saslauthd restart



来做一下验证测试


telnet localhost 25

ehlo localhost <――输入

250-AUTH PLAIN LOGIN

250-AUTH=PLAIN LOGIN

出现这两项表示 sasl 配置成功

然后继续操作

auth login――输入

334 VXNlcm5hbWU6

cG9zdG1hc3RlckBleHRtYWlsLm9yZw==

334 UGFzc3dvcmQ6

ZXh0bWFpbA==

235 2.0.0 Authentication successful

quit

221 2.0.0 Bye


如果出现Authentication successful 表示没有问题了


POP验证




代码:

gedit /etc/courier/authdaemonrc


更改如下一项




代码:

authmodulelist="authmysql"





代码:

cp /etc/courier/authmysqlrc /etc/courier/authmysqlrc_orig

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

gedit /etc/courier/authmysqlrc



内容如下:




代码:

代码:

MYSQL_SERVER            127.0.0.1
MYSQL_USERNAME          root
MYSQL_PASSWORD          123456
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

编辑/etc/courier/pop3d修改下面参数



代码:

MAILDIRPATH=/home/vmail/



配置Courier-IMAP

编辑/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


如果出现error请检查数据库连接,分析mail.log。 一般都是input/output

Tips: chown daemon:vmail /var/run/courier/authdaemon 可能避免错误


测试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.


如果出现问题请仔细分析日志


MDA配置

概念:MDA mail deliver agent其实就是邮件投递代理,postfix本身有很多邮件投递代理,由于我们的环境虚拟域所以可以使用postfix自己的virtual 这个代理,但是它必须创建一个用户来执行投递操作,main.cf中有记录象这样:



代码:

virtual_uid_maps = static:1000

virtual_gid_maps = static:1000

virtual_transport = virtual



下面介绍另一种MDA maildrop


安装Maildrop




代码:

apt-get install maildrop


创建一个文件



代码:

gedit /etc/maildropmysql.config





代码:

hostname 127.0.0.1
port 3306
database extmail
dbuser root
dbpw 123456
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



代码:

gedit /etc/maildroprc





代码:

logfile "/var/log/maildrop.log"



手动创建日志




代码:

gedit /var/log/maildrop.log

chown vmail:vmail /var/log/maildrop.log

chmod 766 /var/log/maildrop.log



创建 /etc/logrotate.d/maildrop


内容为下面:




代码:

/var/log/maildrop.log {
daily
notifempty
missingok
rotate 5
compress
create 766 vmail vmail
sharedscripts
}



编辑/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增加如下参数:




代码:

###### Maildrop config ########
maildrop_destination_recipient_limit = 1
maildrop_destination_concurrency_limit = 2
virtual_transport = maildrop:


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

图形日志extmail




代码:

apt-get install mailgraph

cp -r /var/www/extsuite/extman/addon/mailgraph_ext/ /usr/local/mailgraph_ext



修改/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

update-rc.d mailgraph start 20 2 3 4 5 . stop 20 0 1 6 .


启动服务



代码:

/usr/local/mailgraph_ext/mailgraph-init start


把上面的代码加入到/etc/rc.local中,让系统自动启动




代码:

/etc/init.d/mailgraph start

/etc/init.d/qmonitor start





代码:

chmod 755 /var/run/courier/authdaemon



但是重启之后发现,authdaemon的权限又改会来了


在/etc/rc.local下把这个加了上去




代码:

chmod 755 /var/run/courier/authdaemon



让它开机后自动执行,完工



到此,本系统基本上是安装完毕了。




你可能感兴趣的:(ubuntu,postfix,ExtMail)