我的Postfix+courier+mysql+webmail配置怎么有奇怪的SMTP 535 错误?

Web、Mail、Ftp、DNS、Proxy、VPN、Samba、LDAP 等基础网络服务
回复
yinghailai2009
帖子: 17
注册时间: 2009-05-12 10:02

我的Postfix+courier+mysql+webmail配置怎么有奇怪的SMTP 535 错误?

#1

帖子 yinghailai2009 » 2009-07-29 21:49

根据网上搜到的配置方法

我配置了我的postfix配置过程很顺利,
在公司我用foxmail6.5 能发送邮件到sina.com和公司的域名(假定为,company.com)的邮件
在公司的时候我设的foxmail6.5是默认设置,除了设置了pop3登陆密码意外,别的没有设置就连smtp验证都没有,但是仍然正常.

但是在家里我用foxmail6.5 就不能发送给sina.com的地址,只能发送给company.com的地址,发给sina.com的时候总是报错smtp:535
在家用公司的foxmail6.5的一抹一样的设置就是不能发给外网比如sina.com.

收邮件都正常

我的前辈用他的outlook说是在家也可以发给别的网段邮件.

请问为什么,是不是我的配置有问题?


附:我的配置如下:
------------------------------------------------------------------------------------------------------------------------
作者:王兴宇
版本:0.20
版权:GPL
发布日期:2004-01-29
目录
1. 概述
1.1. 目的
1.2. 更新历史
1.3. TODO
1.4. 鸣谢
2. 系统功能
3. 系统基本前提
4. 配置MySQL
4.1. 运行
4.2. 测试
4.3. 配置
5. 安装pam_mysql
5.1. 下载
5.2. 编译与安装
5.3. 配置
6. 安装Cyrus-SASL
6.1. 下载
6.2. 编译与安装
6.3. 配置
6.4. 运行
7. 安装Postfix
7.1. 下载
7.2. 编译与安装
7.3. 配置
7.4. 运行
7.5. 测试
8. 安装Cyrus-IMAP
8.1. 下载
8.2. 编译与安装
8.3. 配置
8.4. 运行
8.5. 测试
9. 安装IMP
9.1. 下载
9.2. 配置Apache/PHP
9.3. 配置Horde
9.4. 配置Imp
9.5. 配置Turba
9.6. 测试IMP
10. 其它
10.1. 启动脚本
10.2. 整体测试
1. 概述
1.1. 目的
  本文试图介绍如何在一个Linux平 台上安装一套功能完整的邮件系统。这里我们以Postfix做SMTP服务器、Courier-IMAP做POP3/IMAP4服务器、通过Cyrus- SASL对存储在MySQL数据库中的用户进行验证和授权,并且使用IMP来提供一个完善的WEBMAIL界面。
  这个邮件系统的设计目标是提供一个可扩充的、具备大多数功能的邮件系统。
  如果希望使用Cyrus-IMAP做为POP3/IMAP4服务器,可以参阅本文的姊妹篇:http://www.cngnu.org/technology/Postfix_I.html
  本文的最新版本可以在这里找到:http://www.cngnu.org/technology/Postfix_II.html
  有关本文所涉及的技术问题,请到http://www.anti-spam.org.cn/forums/的mail版讨论,我会尽快回复的,请勿就技术问题给我发邮件。
  本文的版权遵循GPL,可以在不删除版权信息和注明修改的情况下任意传播。
1.2. 更新历史
• 2004-01-29 第一次发布,版本0.20。
1.3. TODO
• 增加邮件列表功能
• 增加SSL部分的内容
• 翻译:希望有能力的朋友可以翻译这篇文章为英文,这样国外的朋友也可以看到
1.4. 鸣谢
2. 系统功能
  系统逻辑结构:
+--------------------------------------------------------------+| || 25/25 25/25 110/993 143/995 80/443 || Incoming Outgoing POP3 IMAP WEB-MAIL || /\ /\ /\ /\ /\ || || || || || || || \/ \/ \/ \/ \/ |+---------------------------------+----------------+-----------+| Postfix | | IMP || +------------------+ +-----------+| | Cyrus-SASL | Courier-IMAP |+----------+ +------------------+--------------+ || MailDrop | |authdaemond.mysql |(authmysqlrc) | |+----------+---+------------------+--------------+-------------+| MailDir/ | MySQL | MailDir/ |+----------+-------------------------------------+-------------+
  整个系统对外的界面包括几个部分,用来发信的SMTP、用来收信的POP3和IMAP、以及一个WEB界面的邮件使用系统。这里没有提供WEB界面的管理工具,需要大家自行依据实际需要开发。如果需要商业应用,可以购买CEM产品(http://cngnu.net/products/cem/),其中包括了完善的管理界面和优化的邮件服务器环境。
  MySQL作为系统中存储数据的核心,它存储了用户的信息。这个信息不但用于POP3/IMAP和SMTP AUTH的认证需要,而且也为Postfix提供了本地接收者列表、邮件转发功能和过滤功能开关。
  认证分为两种类型,Postfix中的发信认证是通过SASL对MySQL进行查询进行的;Courier-IMAP的收信认证是通过Courier-IMAP的MySQL支持进行的。
  用户的信件是存储在标准的(Qmail格式)MailDir/中的。Postfix接收到信件后通过MailDrop投递到用户的MailDir/中。Courier-IMAP通过认证后访问MailDir/来读取信件。
3. 系统基本前提
  本文以Linux系统为目标平台,支持多数的Linux平台如RedHat 7.x/8.x/9.x/AS2.1/AS3、Mandrake 8.x/9.x等,理论上也会支持其他的Linux发行版,甚至其他的UNIX系统。
   这里以RedHat Linux Advance Server Enterprise V 3.0 (以下简称AS3)为说明平台。我采用了最基本的AS3安装,只选择了“Web Server”、“Dns Name Server”、“MySQL Database Server”、“Development Tools”和“Kernel Development”等软件包组(“Core”和“Base”组是默认必选的软件包)。
  除此外,还需要额外安装以下RPM:
  1、php-mysql-4.3.2-8.ent.i386.rpm(在CD3)
4. 安装MySQL
4.1. 下载
  AS3默认是只包含MySQL除了服务器程序外的部分的,所以需要从RPMFIND下载MySQL的源RPM重建(最好使用源码包,采用MySQL.com提供的RPM和BIN包都可能在其它使用mysql的部分编译时候出现错误)。
[root@mail root]# cd /usr/src
[root@mail src]# wget ftp://rpmfind.net/linux/redhat/enterpri ... -1.src.rpm
4.2. 编译与安装
[root@mail src]# rpmbuild -bb mysql-3.23.58-1.src.rpm
[root@mail src]# cd redhat/RPMS/i386
[root@mail i386]# rpm -ivh mysql-server-3.23.58-1.i386.rpm
  为提高MySQL的安全性,使之只监听在本地打环端口,修改/etc/my.cnf:
[root@mail i386]# cd
[root@mail root]# vi /etc/my.cnf
  在[mysqld]小节里面添加:
bind-address=127.0.0.1
  并设置其开机时候自动运行:
[root@mail root]# chkconfig --level 0123456 mysqld on
4.3. 运行
  启动命令如下:
[root@mail i386]# /etc/init.d/mysqld start
4.4. 测试
  启动MySQL后,首先检查日志/var/log/messages有无错误信息,然后检查进程,应该有如下进程存在:
[root@mail root]# pstree | grep mysqld
|-safe_mysqld---mysqld
  接着检查端口,应该有如下端口打开:
[root@mail root]# netstat -an | grep LISTEN
tcp  0  0 127.0.0.1:3306  0.0.0.0:*  LISTEN
4.5. 建立数据库
  MySQL安装配置好以后,创建如下SQL脚本mail.sql:
CREATE DATABASE mail;
GRANT ALL ON mail.* TO mail@localhost
IDENTIFIED BY "secret";
FLUSH PRIVILEGES;
USE mail;
CREATE TABLE USER (
ID int(10) unsigned NOT NULL auto_increment,
USERNAME varchar(128) NOT NULL default ,
PASSWORD varchar(40) NOT NULL default ,
CLEAR_PASSWORD varchar(40) NOT NULL default ,
FORWARD varchar(128) NOT NULL default ,
DOMAIN varchar(64) NOT NULL default ,
HOMEDIR varchar(128) NOT NULL default ,
MAILDIR varchar(128) NOT NULL default ,
MAIL varchar(64) NOT NULL default ,
GID int(11) NOT NULL default 450,
UID int(11) NOT NULL default 450,
FILTER varchar(64) NOT NULL default OK,
QUOTA int(11) NOT NULL default 10485760,
STATUS tinyint(4) NOT NULL default 1,
PRIMARY KEY (ID),
UNIQUE KEY USERNAME (USERNAME),
UNIQUE KEY MAIL (MAIL)
) TYPE=MyISAM;
INSERT INTO USER (USERNAME,PASSWORD,CLEAR_PASSWORD,
FORWARD,DOMAIN,HOMEDIR,MAILDIR,MAIL)
VALUES (trueuser,$1$pi.WVgBx$a3dUCzBnbY76jnZlqWQCQ/,testpw,
trueuser,cngnu.org,/data/mail/trueuser,/data/mail/trueuser/Maildir,
trueuser@cngnu.org),
(virtualuser@cngnu.org,$1$pi.WVgBx$a3dUCzBnbY76jnZlqWQCQ/,testpw,
virtualuser@cngnu.org,cngnu.org,/data/mail/cngnu.org/virtualuser,
/data/mail/cngnu.org/virtualuser/Maildir,virtualuser@cngnu.org);
[root@mail root]# mysql < mail.sql
  在MySQL中创建邮件用户数据库,并添加两个测试邮箱:
• 非虚拟域邮箱“trueuser”,密码是“testpw”
• 虚拟域邮箱“virtualuser@cngnu.org”,密码是“testpw”
  上面的mail数据库的USER表用来保存用户信息:
• USERNAME是用户名。USERNAME不但作为认证的字段,而且是本地邮箱查找条件(见下面的Postfix的virtual.mysql)。这里采用了加密密码是为了更好的安全性。对于
o 非虚拟域邮箱:USERNAME字段是邮件的本地部分(“@”前面的部分)
o 虚拟域邮箱:USERNAME字段是邮件地址全称
• PASSWORD 字段是邮箱的MD5-Crypt密码,CLEAR_PASSWORD是明文密码。邮箱的密码是“testpw”,加密后的(MD5-CRYPT)密文是 “$1$pi.WVgBx$a3dUCzBnbY76jnZlqWQCQ/”(可以通过系统的passwd命令来添加一个用户,生成密码,然后从/etc /shadow中复制。)。保存两个密码是由于Cyrus-SASL的mysql认证方式不支持加密的密码,而Courier-IMAP的mysql认证 却使用加密的密码。
• FORWARD字段默认情况下与USERNAME一样,在此情况下,邮件递交到本地邮箱(由于Postfix区 分邮箱的大小写,所以通过这样的一个转发,正好可以消除大小写的区别);如果FORWARD字段是另外一个用户名或者邮件地址,则该邮件被转发到别的用户 或其它邮件地址。
• DOMAIN字段用来快速找出某个域下存在的邮箱,仅为管理方便使用。
• MAILDIR字段用来给MailDrop指出邮件投递那里,HOMEDIR字段是邮件用户的主目录,通常指向一个任意存在的公共位置,不过可以使每个用户都拥有自己的主目录,在其中可以放入maildrop的过滤规则来实现用户级别的过滤。
• MAIL 字段是邮件地址全称。对于非虚拟域邮箱,它包含了本地部分外的域部分;对于虚拟域邮箱,它和USERNAME字段一样。一方面是为了管理方便使用,同时该 字段还用来做maildrop递交和全局过滤控制FILTER的查找条件(见FILTER字段及下面Postfix的filter.mysql)。
• GID字段和UID字段是系统使用的投递用户ID,即MailDrop的运行身份(在Postfix的master.cf指定)。
• FILTER字段用于控制该邮箱是否接受服务器的全局邮件过滤。该值设置为“OK”或为空表示对该邮箱不进行过滤;设置为“DUNNO”表示对该邮箱进行Postfix中定于的全局过滤。该值可以是任何合法的Postfix的access过滤规则。
• PARTITION字段用于指明邮箱存储的Cyrus-IMAP邮件分区。可以建立多个不同的邮件分区。仅为了管理方便使用。
• QUOTA字段指定邮箱的磁盘限额。仅为了管理方便使用。
• STATUS字段用来指示该用户是否有效,可以通过修改该值为0来临时禁止某个用户。
5. 安装Cyrus-SASL
5.1. 下载
  目前多数版本的LINUX中都已经内置了Cyrus-SASL,但是并不符合我们的需要,所以我们需要从rpmfind.net下载Cyrus-SASL的源RPM修改后重建并更新系统的Cyrus-SASL:
  ftp://rpmfind.net/linux/redhat/enterpri ... -3.src.rpm
[root@mail root]# cd /usr/src
[root@mail src]# wget ftp://rpmfind.net/linux/redhat/enterpri ... -3.src.rpm
5.2. 编译与安装
  安装Cyrus-sasl源RPM:
[root@mail src]# rpm -ivh cyrus-sasl-2.1.15-3.src.rpm
  应用以下补丁文件cyrus-sasl.spec.patch:
*** cyrus-sasl.spec 2003-08-22 03:22:37.000000000 +0800
--- /root/cyrus-sasl.spec 2004-01-16 12:56:30.000000000 +0800
***************
*** 5,11 ****
Summary: The Cyrus SASL library.
Name: cyrus-sasl
Version: 2.1.15
! Release: 3
License: Freely Distributable
Group: System Environment/Libraries
Source0: ftp://ftp.andrew.cmu.edu/pub/cyrus-mail ... on}.tar.gz
--- 5,11 ----
Summary: The Cyrus SASL library.
Name: cyrus-sasl
Version: 2.1.15
! Release: 3m
License: Freely Distributable
Group: System Environment/Libraries
Source0: ftp://ftp.andrew.cmu.edu/pub/cyrus-mail ... on}.tar.gz
***************
*** 73,78 ****
--- 73,87 ----
The %{name}-md5 package contains the Cyrus SASL plugins which support
CRAM-MD5 and DIGEST-MD5 authentication schemes.

+ %package mysql
+ Requires: %{name} = %{version}-%{release}
+ Group: System Environment/Libraries
+ Summary: Mysql support for Cyrus SASL.
+
+ %description mysql
+ The %{name}-mysql package contains the Cyrus SASL plugins which support
+ Mysql auxprop authentication schemes.
+
%prep
%setup -q -c -a 2
pushd cyrus-sasl-%{cs1_version}
***************
*** 167,173 ****
--enable-cram \
--enable-digest \
--enable-plain \
! --enable-login
# --enable-auth-sasldb -- EXPERIMENTAL
make sasldir=%{_plugindir2}
popd
--- 176,183 ----
--enable-cram \
--enable-digest \
--enable-plain \
! --enable-login \
! --with-mysql
# --enable-auth-sasldb -- EXPERIMENTAL
make sasldir=%{_plugindir2}
popd
***************
*** 273,278 ****
--- 283,293 ----
%{_plugindir2}/*digestmd5*.so*
%{_plugindir2}/*digestmd5*.la

+ %files mysql
+ %defattr(-,root,root)
+ %{_plugindir2}/*mysql*.so*
+ %{_plugindir2}/*mysql*.la
+
%files gssapi
%defattr(-,root,root)
%{_plugindir}/*gssapi*.so*
***************
*** 300,305 ****
--- 315,321 ----
%{_plugindir2}/*anonymous*.a
%{_plugindir2}/*crammd5*.a
%{_plugindir2}/*digestmd5*.a
+ %{_plugindir2}/*mysql*.a
%{_plugindir2}/*gssapi*.a
%{_plugindir2}/*login*.a
%{_plugindir2}/*plain*.a
  这个补丁主要对原有的Cyrus-SASL库添加了对MySQL认识的支持。
[root@mail src]# cd redhat/SPECS
[root@mail SPECS]# patch -p0 < ../../cyrus-sasl.spec.patch
  如果没有出现错误,然后重建RPM:
[root@mail SPECS]# rpmbuild -bb cyrus-sasl.spec
  重建完成后更新系统的Cyrus-SASL:
[root@mail SPECS]# cd ../RPMS/i386
[root@mail i386]# rm -rf cyrus-sasl-debuginfo*.rpm
[root@mail i386]# rpm -Uvh cyrus-sasl*.rpm
5.3. 配置
  设置Postfix使用SASL的mysql扩展认证来支持smtp auth认证:
[root@mail i386]# vi /usr/lib/sasl2/smtpd.conf
  内容如下:
pwcheck_method: auxprop
mech_list: plain login
mysql_user: mail
mysql_passwd: secret
mysql_hostname: localhost
mysql_database: mail
mysql_statement: select CLEAR_PASSWORD from USER where (USERNAME = %u or MAIL = %u@%r) limit 1
  对于cyrus-sasl-2.1.17版本的sasl,其对mysql、postgresql等数据库的支持已经合并为一个sql扩展,具体的配置语句略有不同。
  整个系统只有Postfix的smtp auth使用了SASL认证。Courier-IMAP的认证使用了它自己的mysql扩展。
6. 安装Maildrop
6.1. 下载
  http://sourceforge.net/projects/courier/
[root@mail i386]# cd /usr/src
[root@mail src]# wget http://heanet.dl.sourceforge.net/source ... .3.tar.bz2
6.2. 编译与安装
  先添加用户maildrop,其UID和GID是mysql数据库字段UID和GID的值:
[root@mail src]# groupadd -g 450 maildrop
[root@mail src]# useradd -g 450 -u 450 -c maildrop -M -d/data/mail -s/no/shell maildrop
  编译maildrop,并增加mysql支持和限额支持:
[root@mail src]# tar -xvjf maildrop-1.6.3.tar.bz2
[root@mail src]# cd maildrop-1.6.3
[root@mail maildrop-1.6.3]# ./configure \
> --without-db --enable-sendmail=/usr/sbin/sendmail \
> --enable-trusted-users=root maildrop \
> --enable-maildropmysql --with-mysqlconfig=/etc/maildrop.mysql \
> --enable-maildirquota --with-trashquota --with-dirsync
[root@mail maildrop-1.6.3]# make
[root@mail maildrop-1.6.3]# make install-strip
[root@mail maildrop-1.6.3]# make install-man
[root@mail maildrop-1.6.3]# cp maildropmysql.config /etc/maildrop.mysql
6.3. 配置
  然后编辑配置文件/etc/maildrop.mysql:
[root@mail maildrop-1.6.3]# vi /etc/maildrop.mysql
  内容如下
hostname localhost
port 3306
socket /var/lib/mysql/mysql.sock
database mail
dbuser mail
dbpass secret
dbtable USER
default_uidnumber 450
default_gidnumner 450
uid_field MAIL
uidnumber_field UID
gidnumber_field GID
maildir_field MAILDIR
homedirectory_field HOMEDIR
quota_field QUOTA
mailstatus_field STATUS
where_clause ""
7. 安装Postfix
7.1. 下载
  http://www.postfix.org/ftp-sites.html
[root@mail maildrop-1.6.3]# cd /usr/src
[root@mail src]# wget http://postfix.energybeam.com/source/of ... .16.tar.gz
7.2. 编译与安装
  如果你的系统上原来有sendmail,先将其停止并将其文件改名:
[root@mail src]# /etc/init.d/sendmail stop
[root@mail src]# chkconfig --level 0123456 sendmail off
[root@mail src]# mv /usr/bin/newaliases /usr/bin/newaliases.orig
[root@mail src]# mv /usr/bin/mailq /usr/bin/mailq.orig
[root@mail src]# mv /usr/sbin/sendmail /usr/sbin/sendmail.orig
  然后添加两个组:postfix和maildrop和一个用户:postfix
[root@mail src]# groupadd -g 400 postfix
[root@mail src]# groupadd -g 401 postdrop
[root@mail src]# useradd -u 400 -g 400 -c postfix -M -d/no/where -s/no/shell postfix
  这里的组和用户的ID是系统中未使用的ID。
  编译Postfix,并支持mysql和sasl:
[root@mail src]# tar -xvzf postfix-2.0.16.tar.gz
[root@mail src]# cd postfix-2.0.16
[root@mail postfix-2.0.16]# make -f Makefile.init makefiles \
> CCARGS=-DUSE_SASL_AUTH -DHAS_MYSQL -I/usr/include/mysql -I/usr/include/sasl \
> AUXLIBS=-L/usr/lib/mysql -L/usr/lib/sasl2 -lmysqlclient -lsasl2 -lz -lm
[root@mail postfix-2.0.16]# make install
  安装时,安装程序会提问一些问题,可以直接按回车采用默认值。
   这里切记要指定正确的SASL2的INCLUDE和LIB位置。由于现在很多linux发行版上都已经带有了sasl,如果不指定的话,很可能会使用了 不同版本的头文件和库,在这种情况下,每次连接SMTP时,smtpd就会发生致命错误“Fatal: SASL per-connection server init...”而崩溃。
  给postfix用户做一个系统别名,并将超级用户的邮箱转发到一个普通用户如tester。使用/etc/postfix/aliases别名数据库:
[root@mail postfix-2.0.16]# cd postfix
[root@mail postfix]# echo root: virtualuser@cngnu.org >> /etc/postfix/aliases
  生成/etc/postfix/aliases别名数据库:
[root@mail postfix]# postalias /etc/postfix/aliases
  生成/etc/postfix/virtual的DB库:
[root@mail postfix]# postmap virtual
  保留db格式的virtual库是为了系统临时增加转发方便起见。
7.3. 配置
  修改/etc/postfix/master.cf中的关于maildrop的配置:
[root@mail postfix]# vi master.cf
  将如下两行:
maildrop unix - n n - - pipe
 flags=DRhu user=vmail argv=/usr/local/bin/maildrop -d ${recipient}
  修改为:
maildrop unix - n n - - pipe
 flags=DRhu user=maildrop argv=/usr/local/bin/maildrop -d ${recipient}
  这里要把maildrop的路径修改为上面安装的maildrop实际安装路径,用户maildrop是我们上面添加过的。 记着flags=...这行前面是以空格缩进的。
[root@mail postfix]# vi main.cf
  修改/etc/postfix/main.cf的配置:
myhostname = mail.cngnu.org
mydomain = cngnu.org
myorigin = $mydomain
mydestination = $mydomain,$myhostname
mynetworks_style = host
alias_maps = hash:/etc/postfix/aliases
alias_database = hash:/etc/postfix/aliases
home_mailbox = Maildir/
mailbox_transport = maildrop
fallback_transport = maildrop
virtual_maps = hash:/etc/postfix/virtual,mysql:/etc/postfix/virtual.mysql
smtpd_sasl_auth_enable = yes
broken_sasl_auth_clients = yes
smtpd_sasl_security_options = noanonymous
smtpd_recipient_restrictions =
permit_mynetworks,
permit_sasl_authenticated,
check_recipient_access mysql:/etc/postfix/filter.mysql,
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,
reject_unauth_destination,
permit
  如果希望支持更多的虚拟域,可以在mydestination参数后面加上你所要支持的域即可。
  通过virtual和virtual.mysql为系统提供了邮箱本地查询表。
  在上面的配置文件里面使用了SASL来进行SMTP发信认证。
   通过smtpd_recipient_restrictions提供了基本的反垃圾邮件功能。首先允许本地网络(这里是本机)和通过SASL认证的用户 可以使用本服务器发信;然后检查每个用户的全局邮件过滤功能是否打开,如果关闭则不进行后面的反垃圾邮件检查;其后是一些Postfix支持的基本反垃圾 邮件功能。
  创建/etc/postfix/virtual.mysql,它提供了本地用户和邮件转发功能。FORWARD字段默认是指 向用户的存储邮箱名的(Courier-IMAP所管理的邮箱名称),即进行本地投递;如果FORWARD字段是另外一个用户名或者邮件地址,则该邮件被 转发到别的用户或其它邮件地址。
[root@mail postfix]# vi virtual.mysql
#
# mysql config file for alias lookups on postfix
#
# the user name and password to log into the mysql server
hosts = localhost
user = mail
password = secret
# the database name on the servers
dbname = mail
# the table name
table = USER
select_field = FORWARD
where_field = USERNAME
additional_conditions = and STATUS = 1 limit 1
[root@mail postfix]# vi filter.virtual
#
# mysql config file for filter flag on postfix
#
# the user name and password to log into the mysql server
hosts = localhost
user = mail
password = secret
# the database name on the servers
dbname = mail
# the table name
table = USER
select_field = FILTER
# OK : ignore filter
# DUNNO : filter
where_field = MAIL
additional_conditions = and STATUS = 1 limit 1
7.4. 运行
  启动命令如下:
[root@mail postfix]# /usr/sbin/postfix start
  可以使用文末所附脚本设置postfix在系统启动时候自动运行。
7.5. 测试Postfix
  启动Postfix后,首先检查日志/var/log/messages有无错误信息,然后检查进程,应该有如下进程存在:检查端口及进程:
[root@mail postfix]# pstree |grep master
|-master-+-pickup
  接着检查端口,应该有如下端口打开:
[root@mail postfix]# netstat -an |grep LISTEN
tcp  0  0 0.0.0.0:25  0.0.0.0:*  LISTEN
  再检测SMTP服务是否正常:
[root@mail postfix]# telnet localhost 25
Trying 127.0.0.1...
Connected to localhost.
Escape character is ^].
220 mail.cngnu.org ESMTP Postfix
QUIT
221 Bye
Connection closed by foreign host.
  使用如下命令测试postfix的SMTP的认证(这里仅测试了“virtualuser@cngnu.org”,“trueuser”请自行测试):
  PLAIN认证方式:
[root@mail postfix]# perl -MMIME::Base64 -e \
> print encode_base64("virtualuser\@cngnu.org\000virtualuser\@cngnu.org\000testpw");
dmlydHVhbHVzZXJAY25nbnUub3JnAHZpcnR1YWx1c2VyQGNuZ251Lm9yZwB0ZXN0cHc=
[root@mail postfix]# telnet localhost 25
Trying 127.0.0.1...
Connected to localhost.
Escape character is ^].
220 mail.cngnu.org ESMTP Postfix
EHLO cngnu
250-mail.cngnu.org
250-PIPELINING
250-SIZE 10240000
250-VRFY
250-ETRN
250-AUTH LOGIN PLAIN
250-AUTH=LOGIN PLAIN
250-XVERP
250 8BITMIME
AUTH PLAIN dmlydHVhbHVzZXJAY25nbnUub3JnAHZpcnR1YWx1c2VyQGNuZ251Lm9yZwB0ZXN0cHc==
235 Authentication successful
QUIT
221 Bye
Connection closed by foreign host.
[root@mail postfix]# perl -MMIME::Base64 -e \
> print encode_base64("trueuser\000trueuser\000testpw");
dHJ1ZXVzZXIAdHJ1ZXVzZXIAdGVzdHB3
  LOGIN认证方式:
[root@mail postfix]# perl -MMIME::Base64 -e \
> print encode_base64("virtualuser\@cngnu.org");
dmlydHVhbHVzZXJAY25nbnUub3Jn
[root@mail postfix]# perl -MMIME::Base64 -e \
> print encode_base64("testpw");
dGVzdHB3
[root@mail postfix]# telnet localhost 25
Trying 127.0.0.1...
Connected to localhost.
Escape character is ^].
220 mail.cngnu.org ESMTP Postfix
EHLO cngnu
250-mail.cngnu.org
250-PIPELINING
250-SIZE 10240000
250-VRFY
250-ETRN
250-AUTH LOGIN PLAIN
250-AUTH=LOGIN PLAIN
250-XVERP
250 8BITMIME
AUTH LOGIN
334 VXNlcm5hbWU6
dmlydHVhbHVzZXJAY25nbnUub3Jn
334 UGFzc3dvcmQ6
dGVzdHB3
235 Authentication successful
QUIT
221 Bye
Connection closed by foreign host.
[root@mail postfix]# perl -MMIME::Base64 -e \
> print encode_base64("trueuser");
dHJ1ZXVzZXI=
[root@mail postfix]# perl -MMIME::Base64 -e \
> print encode_base64("testpw");
dGVzdHB3
  此时,由于还没有安装Courier-IMAP以及创建邮箱,所以还不能提交邮件,请继续下一步。
   这里使用Perl里面的MIME::Base64模块(如果需要安装:perl -MCPAN -e install MIME::Base64;)来取得这个验证串:perl -MMIME::Base64 -e print base64_encode("用户名\000用户名\000密码");来得到MIME-Base64编码的验证串(“\000”是八进制的 ASCII(0)字符)。此外,你也可以使用mmencode来生成,mmencode可以在metamail这个包里面找到。
8. 安装Courier-IMAP
8.1. 下载
  http://sourceforge.net/projects/courier/
[root@mail postfix]# cd /usr/src
[root@mail src]# wget http://umn.dl.sourceforge.net/sourcefor ... .1.tar.bz2
8.2. 编译与安装
  编译Cyrus-IMAP,并取消kerberos支持(在Redhat中,kerberos库有问题,很难编译通过,Mandrake则可以通过;此外,我们也不需要kerberos的支持)和snmp的支持:
[root@mail src]# tar -jxf courier-imapd-2.2.1.tar.ba2
[root@mail src]# cd courier-imapd-2.2.1
[root@mail courier-imapd-2.2.1]# ./configure --with-redhat \
> --disable-root-check --enable-unicode=utf-8,iso-8859-1,gb2312 \
> --with-trashquota --with-dirsync
[root@mail courier-imapd-2.2.1]# make
[root@mail courier-imapd-2.2.1]# make install-strip
[root@mail courier-imapd-2.2.1]# make install-configure
[root@mail courier-imapd-2.2.1]# cp courier-imap.sysvinit /etc/rc.d/init.d/courier-imap
[root@mail courier-imapd-2.2.1]# chmod 755 /etc/rc.d/init.d/courier-imap
[root@mail courier-imapd-2.2.1]# chkconfig --level 0123456 courier-imap on
8.3. 配置
  修改Courier-IMAP的认证配置文件/usr/lib/courier-imap/etc/authdaemonrc:
[root@mail courier-imapd-2.2.1]# cd /usr/lib/courier-imap/etc
[root@mail etc]# vi authdaemonrc
  内容如下,确保只使用mysql认证模块:
authmodulelist="authmysql"
authmodulelistorig="authmysql"
version="authdaemond.mysql"
  然后修改mysql认证模块的配置文件:
[root@mail etc]# vi authmysqlrc
  内容如下:
MYSQL_SERVER localhost
MYSQL_USERNAME mail
MYSQL_PASSWORD secret
MYSQL_SOCKET /var/lib/mysql/mysql.sock
MYSQL_PORT 3306
MYSQL_DATABASE mail
MYSQL_USER_TABLE USER
MYSQL_CRYPT_PWFIELD PASSWORD
MYSQL_CLEAR_PWFIELD CLEAR_PASSWORD
MYSQL_UID_FIELD UID
MYSQL_GID_FIELD GID
MYSQL_LOGIN_FIELD USERNAME
MYSQL_HOME_FIELD HOMEDIR
MYSQL_NAME_FIELD USERNAME
MYSQL_MAILDIR_FIELD MAILDIR
MYSQL_QUOTA_FIELD QUOTA
MYSQL_WHERE_CLAUSE STATUS=1
  编辑IMAP的配置文件imapd,使其自动启动:
[root@mail etc]# vi imapd
  修改其最后一行为YES:
IMAPDSTART=YES
  编辑POP3的配置文件pop3d,使其自动启动:
[root@mail etc]# vi pop3d
  修改其最后一行为YES:
POP3DSTART=YES
8.4. 运行
  启动Courier-IMAP,启动命令如下:
[root@mail etc]# /etc/rc.d/init.d/courier-imap start
  Courier-IMAP的认证进程会自动运行。
8.5. 测试Courier-IMAP
  启动Courier-IMAP后,首先检查日志/var/log/messages和/var/log/imapd.log有无错误信息,然后检查进程,应该有如下进程存在:
[root@mail etc]# pstree |grep authdaemond
|-authdaemond.mys---5*[authdaemond.mys]
[root@mail etc]# pstree |grep courier
|-2*[courierlogger]
|-2*[couriertcpd]
  接着检查端口,应该有如下端口打开:
[root@mail etc]# netstat -an |grep LISTEN
tcp  0  0 0.0.0.0:110  0.0.0.0:*  LISTEN
tcp  0  0 0.0.0.0:143  0.0.0.0:*  LISTEN
  现在创建邮箱。
[root@mail etc]# mkdir /data
[root@mail etc]# chown maildrop:maildrop /data
[root@mail etc]# su -s/bin/bash maildrop
bash-2.05b$ cd /data
bash-2.05b$ mkdir trueuser
bash-2.05b$ /usr/local/bin/maildirmake trueuser/Maildir
bash-2.05b$ mkdir -p cngnu.org/virtualuser
bash-2.05b$ /usr/local/bin/maildirmake cngnu.org/virtualuser/Maildir
  再检测POP3和IMAP服务:
[root@mail etc]# telnet localhost 110
+OK Hello there
USER virtualuser@cngnu.org
+OK Password required.
PASS testpw
+OK Logged in.
QUIT
+OK bye-bye
9. 安装IMP
9.1. 下载
  http://www.horde.org/horde/
  http://www.horde.org/imp/3.2.2/
  http://www.horde.org/turba/
[root@mail etc]# cd /usr/src
[root@mail src]# wget ftp://ftp.horde.org/pub/horde/horde-2.2.4.tar.gz
[root@mail src]# wget ftp://ftp.horde.org/pub/pear/pear-1.1.tar.gz
[root@mail src]# wget ftp://ftp.horde.org/pub/imp/imp-3.2.2.tar.gz
[root@mail src]# wget ftp://ftp.horde.org/pub/turba/turba-1.2.1.tar.gz
9.2. 配置Apache与PHP
  IMP对PHP的环境要求较高。所以通常需要升级PHP包,并安装由Horde定制后的PEAR包。
  修改/etc/php.ini,将register_globals功能打开。
register_globals = On
  安装PEAR包,在AS3中,它位于/usr/share/pear下:
[root@mail src]# tar zxf /usr/src/pear-1.1.tar.gz
[root@mail lib]# cd /usr/share
[root@mail lib]# /bin/cp -Rf /usr/src/pear/* pear
  最后重新启动Apache:
[root@mail lib]# chkconfig --level 0123456 httpd on
[root@mail lib]# /etc/rc.d/init.d/httpd restart
9.3. 配置Horde
  安装Horde:
[root@mail lib]# cd /var/www/html
[root@mail html]# tar zxf /usr/src/horde-2.2.4.tar.gz
[root@mail html]# mv horde-2.2.4 horde
[root@mail html]# cd horde/scripts/db
[root@mail db]# mysql < mysql_create.sql
[root@mail db]# cd ../../config
[root@mail config]# for foo in *.dist; do cp $foo `basename $foo .dist`;done
  然后修改config目录下面的horde.php。
[root@mail config]# vi horde.php
  修改162行:
$conf[prefs][driver] = none;
  为:
$conf[prefs][driver] = sql;
  修改171行至176行,将其注释去掉并写入horde数据库的口令:
// $conf[prefs][params][phptype] = mysql;
// $conf[prefs][params][hostspec] = localhost;
// $conf[prefs][params][username] = horde;
// $conf[prefs][params][password] = *****;
// $conf[prefs][params][database] = horde;
// $conf[prefs][params][table] = horde_prefs;
  为:
$conf[prefs][params][phptype] = mysql;
$conf[prefs][params][hostspec] = localhost;
$conf[prefs][params][username] = horde;
$conf[prefs][params][password] = horde;
$conf[prefs][params][database] = horde;
$conf[prefs][params][table] = horde_prefs;
  这里我们没有修改horde数据库的默认的数据库设置,如果在实际使用中,至少应该取一个比较复杂的密码。
  再来修改config目录下面的registry.php。
, ,
[root@mail config]# vi registry.php
  修改23行至24行,将其注释去掉:
// $this->registry[auth][login] = imp;
// $this->registry[auth][logout] = imp;
  为:
$this->registry[auth][login] = imp;
$this->registry[auth][logout] = imp;
  然后修改119、138行激活IMP和Turba:
status => inactive
  为:
status => active
  最后在浏览器中访问如下URL测试Horde需要的环境是否满足:
http://你的邮件服务器的IP/horde/test.php
  如果发现有红色的提示,可能需要修改你的PHP的安装和配置(参见上一节),然后再重新测试。
9.4. 配置IMP
  安装IMP:
[root@mail config]# cd ..
[root@mail horde]# tar zxf /usr/src/imp-3.2.2.tar.gz
[root@mail horde]# mv imp-3.2.2 imp
[root@mail horde]# cd imp/config
[root@mail config]# for foo in *.dist; do cp $foo `basename $foo .dist`;done
  然后修改config目录里面的conf.php:
[root@mail config]# vi conf.php
  修改37行:
$conf[menu][apps] = array();
  为:
$conf[menu][apps] = array(turba);
  修改57行:
$conf[user][allow_resume_all] = false;
  为:
$conf[user][allow_resume_all] = true;
  修改63行:
$conf[user][allow_resume_all_in_drafts] = false;
  为:
$conf[user][allow_resume_all_in_drafts] = true;
  然后修改prefs.php:
[root@mail config]# vi prefs.php
  将自动维护功能关闭,修改426、427行:
value => 1,
locked => false,
  为:
value => 0,
locked => true,
  再注释773行:
value => ,
  为:
//value => ,
  取消注释774行:
// value => localsql,
  为:
value => localsql,
  最后修改servers.php:
[root@mail config]# vi servers.php
  注释除“cyrus”服务器外的所有服务器配置,然后修改“cyrus”服务器的配置为:
$servers[cyrus] = array(
name => IMAP Server,
server => localhost,
protocol => imap/notls,
port => 143,
folders => mail/,
namespace => ,
maildomain => cngnu.org,
smtphost => mail.cngnu.org,
realm => cngnu.org,
preferred =>
);
9.5. 配置Turba
  安装Turba:
[root@mail config]# cd ../..
[root@mail horde]# tar zxf /usr/src/turba-1.2.1.tar.gz
[root@mail horde]# mv turba-1.2.1 turba
[root@mail horde]# cd turba/config
[root@mail config]# for foo in *.dist; do cp $foo `basename $foo .dist`;done
  然后修改config目录里面的conf.php:
[root@mail config]# vi conf.php
  修改32行:
$conf[menu][apps] = array();
  为:
$conf[menu][apps] = array(imp);
  然后修改config目录里面的sources.php:
[root@mail config]# vi sources.php
  修改146行:
password => *****;
  为:
password => horde;
  最后,添加turba数据库表:
[root@mail config]# cd ../scripts/drivers
[root@mail config]# mysql horde
9.6. 测试IMP
  最后在浏览器中访问如下URL:
http://你的邮件服务器的IP/horde/
  输入用户名virtualuser@cngnu.org和密码testpw登录(或trueuser)。
10. 其他
10.1. 启动脚本
  Courier-IMAP已经有了启动脚本,只需要为Postfix编写一个启动脚本postfix即可:
#!/bin/bash## mailsys This shell script takes care of starting and stopping Postfix # author : xingyu.wang 2004/1/28## chkconfig: 2345 80 30# description: Postfix is a Mail Transport Agent, which is the program# that moves mail from one machine to another.## processname: mailsys# pidfile: /var/run/postfix.pid# Source function library.. /etc/rc.d/init.d/functions# Source networking configuration.. /etc/sysconfig/network# Check that networking is up.[ ${NETWORKING} = "no" ] %26amp;%26amp; exit 0[ -f /usr/sbin/postfix ] || exit 0RETVAL=0prog="Postfix"start() { # Start daemons. echo -n $"Starting $prog: " /usr/sbin/postfix start > /dev/null 2>%26amp;1 %26amp; RETVAL=$? if [ $RETVAL -eq 0 ]; then touch /var/lock/subsys/postfix success $"$prog start" else failure $"$prog start failure" fi echo return $RETVAL}stop() { # Stop daemons. echo -n $"Shutting down $prog: " /usr/sbin/postfix stop > /dev/null 2>%26amp;1 %26amp; RETVAL=$? if [ $RETVAL -eq 0 ]; then rm -f /var/lock/subsys/postfix success $"$prog stop" else failure $"$prog stop failure" fi echo return $RETVAL}# See how we were called.case "$1" in start) start ;; stop) stop ;; restart|reload) stop start RETVAL=$? ;; *) echo $"Usage: $0 {start|stop|restart}" exit 1esacexit $RETVAL
[root@mail root]# chmod 755 /etc/rc.d/init.d/postfix
[root@mail root]# chkconfig --level 0123456 postfix on
[root@mail root]# chkconfig --level 0123456 sendmail off
10.2. 整体测试
  创建邮箱后,测试发信功能:
[root@mail root]# mail trueuser
Subject: test by me
this is a test.
.
CC:
[root@mail root]# mailq
Mail queue is empty
[root@mail root]# tail /var/log/maillog
  使用mailq来查看邮件队列是否有错误,并查看/var/log/maillog是否有错误信息。如果一切正常,说明信件已经发送到trueuser了。
  测试收信,先测试POP3:
[root@mail root]# telnet localhost 110
+OK hello there
USER trueuser
+OK Password required.
PASS testpw
+OK Logged in.
LIST
1 400
TOP 1 10
Return-Path:
Delivered-To:
Received: by mail.cngnu.org (Postfix, from userid 0)
id 6A7C4CCCF; Mon, 26 Jan 2004 21:27:23 +0800 (CST)
To: trueuser@cngnu.org
Subject: test by me
Message-Id: <20040126212723.6A7C4CCCF@mail.cngnu.org>
Date: Mon, 26 Jan 2004 21:27:23 +0800 (CST)
From: root@cngnu.org (root)
this is a test.
.
QUIT
+OK
  最后测试IMP,在浏览器中访问如下URL:
http://你的IMP服务器的IP/horde/
  输入用户名trueuser和密码testpw登录。
  你也可以使用任何其它的邮件客户端程序来测试,如kmail、Outlook Express等等。

文章整理:西部数码--专业提供域名注册、虚拟主机服务
http://www.west263.com
以上信息与文章正文是不可分割的一部分,如果您要转载本文章,请保留以上信息,谢谢!
yinghailai2009
帖子: 17
注册时间: 2009-05-12 10:02

Re: 我的Postfix+courier+mysql+webmail配置怎么有奇怪的SMTP 535 错误?

#2

帖子 yinghailai2009 » 2009-07-29 21:58

补充:我用我配的WebMail发没有问题
回复