debian+postfix+dovecot+squirrelmail安装配置笔记
系统和软件安装如下:
1.debian4.0
2.postfix(MTA)提供smtp功能
3.postfix-mysql提供postfix到mysql映射支持
4.MYSQL用户数据库存储
5.dovecot(POP3+IMAP+SASL)提供pop3+imap+(smtp sasl)
6.amavisd-new libclass-dbi-mysql-perl spamassassin clamav-daemon cpio arj zoo nomarch lzop cabextract pax lha unrar
垃圾邮件过虑及邮件病毒过虑
7.openssl提供SSL验证
8.phpmyadmin libapache2-mod-php5 php5-mysql提供web 方式管理mysql数据库存及数据.
9.squirrelmail(MAIL WEB)提供web mail接口,自动装上apache
debian 中安装软件用aptitude install 或apt-get install 比windows 还简单,在这里就不占篇幅了,不会的可以上网找一下。
下面是MYSQL数据库的创建:
创建数据库及表
mysqladmin password 2006 root的密码为:2006
mysqladmin -p create mail创建一个为mail的数据库
mysql>
GRANT Select ON mail.*
TO mailuser@localhost
IDENTIFIED BY '2007';
exit
创建一个mailuser的用户密码为:2007只有对mail数据库存查询权限
创建虚拟虚拟域表:domains
mysql>
Create TABLE `domains` (
id INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
name VARCHAR(50) NOT NULL
) ENGINE = InnoDB;
创建虚拟用户表:users
Create TABLE users (
id int(11) NOT NULL AUTO_INCREMENT PRIMARY KEY,
domain_id INT(11) NOT NULL,
user VARCHAR(40) NOT NULL,
password VARCHAR(32) NOT NULL,
CONSTRAINT UNIQUE_EMAIL UNIQUE (domain_id,user),
FOREIGN KEY (domain_id) REFERENCES domains(id) ON Delete CASCADE
) ENGINE = InnoDB;
创建 view_users表 方便查询及以后设置验证.
mysql>
Create VIEW view_users AS
Select users.user AS user, CONCAT(users.user, '@', domains.name) AS email,
users.password
FROM users
LEFT JOIN domains ON users.domain_id=domains.id;
创建虚拟别名表:aliases
Create TABLE aliases(
id int(11) NOT NULL AUTO_INCREMENT PRIMARY KEY,
domain_id INT(11) NOT NULL,
source VARCHAR(20) NOT NULL,
destination VARCHAR(80) NOT NULL,
FOREIGN KEY (domain_id) REFERENCES domains(id) ON Delete CASCADE
) ENGINE = InnoDB;
Create VIEW view_aliases AS
Select CONCAT(aliases.source, '@', domains.name) AS email,
destination
FROM aliases
LEFT JOIN domains ON aliases.domain_id=domains.id;
创建虚拟域映射文件:
/etc/postfix/virtual-mailbox-domains.cf
user = mailuser
password = 2007
hosts = 127.0.0.1
dbname = mail
query = Select 1 FROM domains Where name='%s'
创建虚拟邮箱映射文件
/etc/postfix/virtual-mailbox-maps.cf
user = mailuser
password = 2007
hosts = 127.0.0.1
dbname = mail
query = Select 1 FROM view_users Where email='%s'
创建虚拟别名映射文件
/etc/postfix/virtual-alias-maps.cf
user = mailuser
password = 2007
hosts = 127.0.0.1
dbname = mail
query = Select destination FROM view_aliases Where email='%s'
/etc/postfix/virtual-email2email.cf
user = mailuser
password = 2007
hosts = 127.0.0.1
dbname = mail
query = Select email FROM view_users Where email='%s'
$>postconf -e virtual_mailbox_domains=mysql:/etc/postfix/virtual-mailbox-domains.cf
$>postconf -e virtual_mailbox_maps=mysql:/etc/postfix/virtual-mailbox-maps.cf
$>postconf -e virtual_alias_maps=mysql:/etc/postfix/virtual-alias-maps.cf,mysql:/etc/postfix/virtual-email2email.cf
$> groupadd -g 5000 vmail
$> useradd -g vmail -u 5000 vmail -d /home/vmail -m
$> postconf -e virtual_uid_maps=static:5000
$> postconf -e virtual_gid_maps=static:5000
为了保障*.cf文件的安全,因内置密码;
chgrp postfix /etc/postfix/virtual-*.cf
chmod u=rw,g=r,o= /etc/postfix/virtual-*.cf
配置dovecot
为了让postfix用dovecot传送邮件在/etc/postfix/master.cf下添加以下服务:
dovecot unix - n n - - pipe
flags=DRhu user=vmail:vmail argv=/usr/lib/dovecot/deliver -d ${recipient}
为了让postfix用dovecot作虚拟传输在main.cf中添加以下项
$> postconf -e virtual_transport=dovecot
$> postconf -e dovecot_destination_recipient_limit=1
配置dovecot.conf
/etc/dovecot/dovecot.conf
添加以下服务支持
protocols = imap imaps pop3 pop3s
不去除明文密码认证
disable_plaintext_auth = no
告诉dovecot邮件是以maildir形式放在/home/vmail/域/用户
mail_location = maildir:/home/vmail/%d/%n
设定认证机制
mechanisms = plain login
告诉dovecot密码在sql数据库中
passdb sql {
args = /etc/dovecot/dovecot-sql.conf
}
和mail_location相似,当用户取邮件时会以日志的形式记录下来
userdb static {
args = uid=5000 gid=5000 home=/home/vmail/%d/%n allow_all_users=yes
}
master部分将通过用户的数据库存信息把新的邮件保存在用户的邮箱中
socket listen {
master {
path = /var/run/dovecot/auth-master
mode = 0600
user = vmail
}
client {
path = /var/spool/postfix/private/auth
mode = 0660
user = postfix
group = postfix
}
}
这部份需要自已定制:dovecot的LDA比postfix自带的LDA功能强大的多,它可设定配额,和邮件过滤,
protocol lda {
log_path = /home/vmail/dovecot-deliver.log
auth_socket_path = /var/run/dovecot/auth-master
postmaster_address = wxy1@wxy.com
mail_plugins = cmusieve
global_script_path = /home/vmail/globalsieverc
配置dovecot-sql.conf
/etc/dovecot/dovecot-sql.conf
driver = mysql
connect = host=127.0.0.1 dbname=mail user=mailuser password=2007
default_pass_scheme = PLAIN
password_query = Select email as user, password FROM view_users Where user='%u';
改变dovecot.conf的权限,设只vmail 组的用户及root用名可以读取
$> chgrp vmail /etc/dovecot/dovecot.conf
$> chmod g+r /etc/dovecot/dovecot.conf
配置smtp验证(sasl)
$> postconf -e smtpd_sasl_type=dovecot
$> postconf -e smtpd_sasl_path=private/auth
$> postconf -e smtpd_sasl_auth_enable=yes
$> postconf -e smtpd_recipient_restrictions=permit_mynetworks,permit_sasl_authenticated,reject_unauth_destination
九、配置webmail
ln -s /usr/share/squirrelmail /var/www/mail
查看 web server: Apache2 是否已启动:
netstat -an |grep :80
tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN
这时可以应该可以用http://IP/mail 访问webmail
如果你想个人的webmail界面是简体中文,请在输入邮箱及密码登录邮箱后,Options->Display Preferences->Language:->Chinese Simple。
如果想将webmail的界面默认为简体中文,请执行/etc/squirrelmail/conf.pl,输入10,可以看到如下界面:
SquirrelMail Configuration : Read: config.php (1.4.0)
---------------------------------------------------------
Language preferences
1. Default Language : en_US
2. Default Charset : iso-8859-1
3. Enable lossy encoding : false
设置成类似:
SquirrelMail Configuration : Read: config.php (1.4.0)
---------------------------------------------------------
Language preferences
1. Default Language : zh_CN
2. Default Charset : GB2312
3. Enable lossy encoding : false
重启web服务:
/etc/init.d/apache2 restart
Forcing reload of web server: Apache2.
再用http://IP/mail访问web mail,可以发现squirrelmail的默认语言已经变成了简体中文了。
注:squirrelmail支持用户修改密码、自动回复、来电提醒等相当多的扩展功能请至squirrelmail网站下载相应的插件安装包就可以了。http://www.squirrelmail.org
有不对之处请多指教!
1.debian4.0
2.postfix(MTA)提供smtp功能
3.postfix-mysql提供postfix到mysql映射支持
4.MYSQL用户数据库存储
5.dovecot(POP3+IMAP+SASL)提供pop3+imap+(smtp sasl)
6.amavisd-new libclass-dbi-mysql-perl spamassassin clamav-daemon cpio arj zoo nomarch lzop cabextract pax lha unrar
垃圾邮件过虑及邮件病毒过虑
7.openssl提供SSL验证
8.phpmyadmin libapache2-mod-php5 php5-mysql提供web 方式管理mysql数据库存及数据.
9.squirrelmail(MAIL WEB)提供web mail接口,自动装上apache
debian 中安装软件用aptitude install 或apt-get install 比windows 还简单,在这里就不占篇幅了,不会的可以上网找一下。
下面是MYSQL数据库的创建:
创建数据库及表
mysqladmin password 2006 root的密码为:2006
mysqladmin -p create mail创建一个为mail的数据库
mysql>
GRANT Select ON mail.*
TO mailuser@localhost
IDENTIFIED BY '2007';
exit
创建一个mailuser的用户密码为:2007只有对mail数据库存查询权限
创建虚拟虚拟域表:domains
mysql>
Create TABLE `domains` (
id INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
name VARCHAR(50) NOT NULL
) ENGINE = InnoDB;
创建虚拟用户表:users
Create TABLE users (
id int(11) NOT NULL AUTO_INCREMENT PRIMARY KEY,
domain_id INT(11) NOT NULL,
user VARCHAR(40) NOT NULL,
password VARCHAR(32) NOT NULL,
CONSTRAINT UNIQUE_EMAIL UNIQUE (domain_id,user),
FOREIGN KEY (domain_id) REFERENCES domains(id) ON Delete CASCADE
) ENGINE = InnoDB;
创建 view_users表 方便查询及以后设置验证.
mysql>
Create VIEW view_users AS
Select users.user AS user, CONCAT(users.user, '@', domains.name) AS email,
users.password
FROM users
LEFT JOIN domains ON users.domain_id=domains.id;
创建虚拟别名表:aliases
Create TABLE aliases(
id int(11) NOT NULL AUTO_INCREMENT PRIMARY KEY,
domain_id INT(11) NOT NULL,
source VARCHAR(20) NOT NULL,
destination VARCHAR(80) NOT NULL,
FOREIGN KEY (domain_id) REFERENCES domains(id) ON Delete CASCADE
) ENGINE = InnoDB;
Create VIEW view_aliases AS
Select CONCAT(aliases.source, '@', domains.name) AS email,
destination
FROM aliases
LEFT JOIN domains ON aliases.domain_id=domains.id;
创建虚拟域映射文件:
/etc/postfix/virtual-mailbox-domains.cf
user = mailuser
password = 2007
hosts = 127.0.0.1
dbname = mail
query = Select 1 FROM domains Where name='%s'
创建虚拟邮箱映射文件
/etc/postfix/virtual-mailbox-maps.cf
user = mailuser
password = 2007
hosts = 127.0.0.1
dbname = mail
query = Select 1 FROM view_users Where email='%s'
创建虚拟别名映射文件
/etc/postfix/virtual-alias-maps.cf
user = mailuser
password = 2007
hosts = 127.0.0.1
dbname = mail
query = Select destination FROM view_aliases Where email='%s'
/etc/postfix/virtual-email2email.cf
user = mailuser
password = 2007
hosts = 127.0.0.1
dbname = mail
query = Select email FROM view_users Where email='%s'
$>postconf -e virtual_mailbox_domains=mysql:/etc/postfix/virtual-mailbox-domains.cf
$>postconf -e virtual_mailbox_maps=mysql:/etc/postfix/virtual-mailbox-maps.cf
$>postconf -e virtual_alias_maps=mysql:/etc/postfix/virtual-alias-maps.cf,mysql:/etc/postfix/virtual-email2email.cf
$> groupadd -g 5000 vmail
$> useradd -g vmail -u 5000 vmail -d /home/vmail -m
$> postconf -e virtual_uid_maps=static:5000
$> postconf -e virtual_gid_maps=static:5000
为了保障*.cf文件的安全,因内置密码;
chgrp postfix /etc/postfix/virtual-*.cf
chmod u=rw,g=r,o= /etc/postfix/virtual-*.cf
配置dovecot
为了让postfix用dovecot传送邮件在/etc/postfix/master.cf下添加以下服务:
dovecot unix - n n - - pipe
flags=DRhu user=vmail:vmail argv=/usr/lib/dovecot/deliver -d ${recipient}
为了让postfix用dovecot作虚拟传输在main.cf中添加以下项
$> postconf -e virtual_transport=dovecot
$> postconf -e dovecot_destination_recipient_limit=1
配置dovecot.conf
/etc/dovecot/dovecot.conf
添加以下服务支持
protocols = imap imaps pop3 pop3s
不去除明文密码认证
disable_plaintext_auth = no
告诉dovecot邮件是以maildir形式放在/home/vmail/域/用户
mail_location = maildir:/home/vmail/%d/%n
设定认证机制
mechanisms = plain login
告诉dovecot密码在sql数据库中
passdb sql {
args = /etc/dovecot/dovecot-sql.conf
}
和mail_location相似,当用户取邮件时会以日志的形式记录下来
userdb static {
args = uid=5000 gid=5000 home=/home/vmail/%d/%n allow_all_users=yes
}
master部分将通过用户的数据库存信息把新的邮件保存在用户的邮箱中
socket listen {
master {
path = /var/run/dovecot/auth-master
mode = 0600
user = vmail
}
client {
path = /var/spool/postfix/private/auth
mode = 0660
user = postfix
group = postfix
}
}
这部份需要自已定制:dovecot的LDA比postfix自带的LDA功能强大的多,它可设定配额,和邮件过滤,
protocol lda {
log_path = /home/vmail/dovecot-deliver.log
auth_socket_path = /var/run/dovecot/auth-master
postmaster_address = wxy1@wxy.com
mail_plugins = cmusieve
global_script_path = /home/vmail/globalsieverc
配置dovecot-sql.conf
/etc/dovecot/dovecot-sql.conf
driver = mysql
connect = host=127.0.0.1 dbname=mail user=mailuser password=2007
default_pass_scheme = PLAIN
password_query = Select email as user, password FROM view_users Where user='%u';
改变dovecot.conf的权限,设只vmail 组的用户及root用名可以读取
$> chgrp vmail /etc/dovecot/dovecot.conf
$> chmod g+r /etc/dovecot/dovecot.conf
配置smtp验证(sasl)
$> postconf -e smtpd_sasl_type=dovecot
$> postconf -e smtpd_sasl_path=private/auth
$> postconf -e smtpd_sasl_auth_enable=yes
$> postconf -e smtpd_recipient_restrictions=permit_mynetworks,permit_sasl_authenticated,reject_unauth_destination
九、配置webmail
ln -s /usr/share/squirrelmail /var/www/mail
查看 web server: Apache2 是否已启动:
netstat -an |grep :80
tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN
这时可以应该可以用http://IP/mail 访问webmail
如果你想个人的webmail界面是简体中文,请在输入邮箱及密码登录邮箱后,Options->Display Preferences->Language:->Chinese Simple。
如果想将webmail的界面默认为简体中文,请执行/etc/squirrelmail/conf.pl,输入10,可以看到如下界面:
SquirrelMail Configuration : Read: config.php (1.4.0)
---------------------------------------------------------
Language preferences
1. Default Language : en_US
2. Default Charset : iso-8859-1
3. Enable lossy encoding : false
设置成类似:
SquirrelMail Configuration : Read: config.php (1.4.0)
---------------------------------------------------------
Language preferences
1. Default Language : zh_CN
2. Default Charset : GB2312
3. Enable lossy encoding : false
重启web服务:
/etc/init.d/apache2 restart
Forcing reload of web server: Apache2.
再用http://IP/mail访问web mail,可以发现squirrelmail的默认语言已经变成了简体中文了。
注:squirrelmail支持用户修改密码、自动回复、来电提醒等相当多的扩展功能请至squirrelmail网站下载相应的插件安装包就可以了。http://www.squirrelmail.org
有不对之处请多指教!
-------------------------------------------------
!!!作者:木由水 http://www.cnblogs.com/muyoushui