您的位置:首页 > 其它

ubuntu postfix安装问题及解决办法

2011-12-19 16:22 225 查看
http://hi.baidu.com/truetruelove/blog/item/adf3099711b0f76454fb9653.html

从8月22日凌晨1点多熬到早上9点半,终于搞定发信收信。实在郁闷,刚接触postfix, 没想到这么麻烦。总结下问题和解决办法.

出现各种错误的主要原因:各种目录和文件权限问题,smtp和pop3密码验证 , 参数配置有误。

postconf -m 显示postfix安装的模块, 提示不支持mysql时,看看有没有把mysql编译进去

解决办法:开启日志,查看/var/log/mail.log, /var/log/syslog

这个命令可以测试收信的验证过程,一定要学会利用这个东东:

authtest -s login test@test.com password

如果验证成功会看到如下内容,不成功则看日志。下面显示的uid,gid一定要和配置文件对上

Authenticated: test@test.com (uid 5000, gid 5000)

Home Directory: /var/mail/test.com/test

Maildir: /var/mail/test.com/test/Maildir/

Quota: 104857600S

Encrypted Password: $1$testtest$6TbcZk/fddcpSk6664LWak2N/

Cleartext Password: 这里显示明文密码
由于不能自动生成邮件目录,所以需要手工生成一下,不然收不了信。

进到/var/mail/test.com/test运行下面的命令会生成test用户的目录,邮件目录默认是Maildir/

maildirmake Maildir

我的配置: SMTP用sasl加密,SMTP和pop3都配置通过courier-authdaemon连接mysql验证. 表结构和数据来源于extman(密码是用md5crypt加密的, 用maildrop投递邮件.

extmail密码设置。这有密码格式说明:http://www.extmail.org/docs/Extmail_Parameter_Intro

1. $1$hhhhhh$xxxxxxxxxxx

该格式以md5()结果为基础,用一串hhhhhh(随机数)的hash对md5进行加密得到的密码,xxxxxxxxxxxxx 就是md5密文数据,它的特征是以$1$为前缀,符合此说明的格式就是md5crypt。

例:$1$187665$G.H.mgUc6NDNY

用如下php代码可以正确生成密码, 然后拿去更新mailbox表里的密码。extman默认密码为extmail

<?php

//两$符号中间的数字是随机的,可以任意设置,不高于12位

$salt ='$1$187665$';

$password = 'yourpassword';

$password = crypt($password, $salt);

echo $password;

?>
我的设置:以test@test.com(即邮箱登录用户名)邮箱为例, 基目录为/var/mail/, 域为test.com。

邮件保存目录: /var/mail/test.com/test

用户和组:固定使用vmail, uid,gid都是5000

切记:所有配置文件里mysql主机地址不要设为localhost应该设成127.0.0.1, 不然有可能连接不上mysql。
1.authdaemon设置

authdaemon配置文件:/etc/courier/authdaemonrc,/etc/courier/authmysqlrc

把authdaemonrc里的DEBGU_LOGIN设置为2, 开启登录调试,在/var/log/mail.*,/var/log/syslog里可以查看登录过程中出的错。日志很有用的.

重点注意:

(1)/var/run/courier/authdaemon/目录需要vmail有权限访问,不然连接不上authdaemon

(2)authmysqlrc里uid,gid的设置一定要对,我是固定为5000。如果从表里查uid,gid一定和vmail用户对上. 不然maildrop没法投递信

(3)切记切记:authmysqlrc里不能用tab要用空格,行尾不能有空格。下面是我的全部配置。

MYSQL_SERVER 127.0.0.1

MYSQL_USERNAME test

MYSQL_PASSWORD test

MYSQL_DATABASE test

MYSQL_USER_TABLE mailbox

#MYSQL_CLEAR_PWFIELD password

MYSQL_UID_FIELD 5000

MYSQL_GID_FIELD 5000

MYSQL_LOGIN_FIELD username

MYSQL_HOME_FIELD /var/mailbox/

#MYSQL_MAILDIR_FIELD concat('/var/mail/',substring_index(email,'@',1),'/')

MYSQL_MAILDIR_FIELD maildir

MYSQL_SOCKET /var/run/mysqld/mysqld.sock

MYSQL_PORT 3306

MYSQL_CRYPT_PWFIELD password

MYSQL_NAME_FIELD name

MYSQL_QUOTA_FIELD quota

MYSQL_SELECT_CLAUSE SELECT username,password,"",5000,5000,concat('/var/mail/',homedir), concat('/var/mail/',maildir),quota, name FROM mailbox WHERE username='$(local_part)@$(domain)'

2.postfix设置

map文件我就不写了,这只写主要配置文件。

/etc/postfix/main.cf

/etc/postfix/master.cf

/etc/postfix/sasl/smtpd.conf 这个没有自己加,CentOS在/usr/lib/sasl2/目录下

重点注意:

(1)不能把虚拟邮箱域加到mydestination里

(2)用maildrop需要在main.cf里加上 maildrop_destination_recipient_limit=1

(3)postfix默认会chroot到/var/spool/目录去运行,我这里配置smtpd不chroot,不然很麻烦。

master.cf改动

smtp把chroot下面改为n不使用chroot

maildrop去掉,改为下面的

maildrop unix - n n - - pipe

flags=DRhu user=vmail argv=maildrop -d ${user}@${nexthop} ${recipient} {$user} ${extension} ${nexthop}

以下是smtpd.conf文件的全部配置,//以后是我加的注释。我设为使用authdaemon验证和pop3收信统一验证过程

mech_list:plain login //这设置为普通但mysql里密码是md5crypt加密过的, 不使用明文密码

pwcheck_method: authdaemond

authdaemond_path: /var/run/courier/authdaemon/socket //这个路径一定要对不然连不上authdaemon

allownonymouslogin:no //不允许匿名登录

allowplaintext:yes

log_level:7 //开启调试可以在/var/mail.*,/var/log/syslog里查看登录时的信息
/etc/postfix/main.cf 全部配置

alias_database = hash:/etc/aliases

alias_maps = hash:/etc/aliases

append_dot_mydomain = no

biff = no

broken_sasl_auth_clients = yes

config_directory = /etc/postfix

home_mailbox = Maildir/

inet_interfaces = all

mailbox_size_limit = 1024000000

message_size_limit = 52428800

mydestination = localhost, localhost.localdomain, localhost

myhostname = localhost

mynetworks = 127.0.0.0/8

myorigin = /etc/mailname

readme_directory = /usr/share/doc/postfix

recipient_delimiter = +

relayhost =

smtp_tls_session_cache_database = btree:${data_directory}/smtp_scache

smtpd_banner = $myhostname ESMTP $mail_name (Ubuntu)

smtpd_client_restrictions = permit_sasl_authenticated

smtpd_recipient_restrictions = permit_sasl_authenticated,permit_mynetworks,reject_unauth_destination, reject_invalid_hostname, reject_non_fqdn_hostname, reject_unknown_sender_domain, reject_non_fqdn_sender, reject_non_fqdn_recipient, reject_unknown_recipient_domain,
reject_unauth_pipelining

smtpd_sasl_auth_enable = yes

smtpd_sasl_security_options = noanonymous

smtpd_tls_cert_file = /etc/ssl/certs/ssl-cert-snakeoil.pem

smtpd_tls_key_file = /etc/ssl/private/ssl-cert-snakeoil.key

smtpd_tls_session_cache_database = btree:${data_directory}/smtpd_scache

smtpd_use_tls = yes

virtual_alias_domains =

virtual_alias_maps = mysql:/etc/postfix/mysql_virtual_alias_maps.cf

virtual_gid_maps = static:5000

virtual_mailbox_base = /var/mail/

virtual_mailbox_domains = mysql:/etc/postfix/mysql_virtual_domains_maps.cf

virtual_mailbox_limit = 1024000000

virtual_mailbox_maps = mysql:/etc/postfix/mysql_virtual_mailbox_maps.cf

virtual_transport = maildrop:

virtual_uid_maps = static:5000

maildrop_destination_recipient_limit=1
参考:

http://www.extmail.org/docs/extmail_solution_linux/

http://hi.baidu.com/netwrom/blog/item/210656fa8de3a11e6d22ebe9.html

http://howtoforge.com/virtual_postfix_mysql_quota_courier

密码格式说明

http://www.extmail.org/docs/Extmail_Parameter_Intro
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐