`

CentOS6.4邮件配置一: postfix + dovecot + mysql + postfixadmin + Roundcubemail

 
阅读更多
参考文章:
----------------------------

可以考虑:
Posty —— Postfix 和 Dovecot 的管理工具 http://www.oschina.net/p/posty
Posty 是一款基于 Web 的 Postfix & Dovecot 管理工具,功能模块包括:API、CLI 和 WebUI。

基于Centos6.2 X64系统下的邮件系统(一) http://205498.blog.51cto.com/195498/844868
基于Centos6.2 X64系统下的邮件系统(二)http://205498.blog.51cto.com/195498/844877  包含杀毒等软件的安装
hmailServer搭建(整合roundcubemail和squirrelmail)http://www.360doc.com/content/10/1109/13/4171006_67887489.shtml
Postfix指定smtp认证客户端发送邮件不成功?
http://bbs.chinaunix.net/thread-4099484-1-1.html

构建Linux系统下的安全Postfix电子邮件服务 http://www.searchsecurity.com.cn/showcontent_73728.htm

如果需要配置DNS,可以参考: http://panyongzheng.iteye.com/blog/1882011

注意:重启,要检查resolv.conf问题

关闭/禁用SELinux
sudo gedit /etc/selinux/config
修改成  SELINUX=disable 禁用SeLinux;修改成  SELINUX=enforcing 使用SeLinux
主意,这个会引起后面的第6个问题。

CentOS安装扩展:
sudo yum install gcc kernel-devel kernel-headers dkms make bzip2 perl

配置iptables:
sudo gedit /etc/sysconfig/iptables
-A INPUT -m state --state NEW -m tcp -p tcp --dport 25 -j ACCEPT
-A INPUT -m state --state NEW -m tcp -p tcp --dport 53 -j ACCEPT
-A INPUT -m state --state NEW -m tcp -p tcp --dport 110 -j ACCEPT
-A INPUT -m state --state NEW -m tcp -p tcp --dport 80 -j ACCEPT
-A INPUT -m state --state NEW -m tcp -p tcp --dport 1024 -j ACCEPT
-A INPUT -m state --state NEW -m tcp -p tcp --dport 1025 -j ACCEPT
-A INPUT -m state --state NEW -m tcp -p tcp --dport 4190 -j ACCEPT
sudo service iptables restart

软件安装:
sudo yum -y install telnet
sudo yum -y install postfix* dovecot*
sudo yum -y install httpd mysql mysql-server mysql-devel php php-mysql
sudo yum -y install php-mbstring php-imap php-xml
sudo yum install pam-devel
或者:
sudo yum -y install telnet postfix* dovecot* httpd mysql mysql-server mysql-devel php php-mysql php-mbstring php-imap php-xml pam-devel
sudo chkconfig postfix on
sudo chkconfig dovecot on
sudo chkconfig httpd on
sudo chkconfig mysqld on
sudo gedit /etc/httpd/conf/httpd.conf //找到#ServerName www.example.com:80   把#去掉
sudo service postfix restart
sudo service dovecot restart
sudo service httpd restart
sudo service mysqld restart

注意:以上自动开机运行和启动服务很重要,否则可能会碰到乱七八糟的问题

创建一个vmail用户,用作管理虚拟邮箱的文件夹
sudo useradd -u 2000 -d /var/vmail -m -s /sbin/nologin vmail

创建mail数据库和账户
mysqladmin -uroot password 'root'
mysql -h localhost -uroot -p
mysql> GRANT ALL PRIVILEGES ON mail.* TO root@localhost IDENTIFIED BY 'root';
mysql> create database mail;
mysql> GRANT ALL PRIVILEGES ON mail.* TO admin@"localhost" IDENTIFIED BY '123123' WITH GRANT OPTION;
mysql> flush privileges;

下载postfixadmin:
http://sourceforge.net/projects/postfixadmin/files/postfixadmin/postfixadmin-2.3.6/postfixadmin-2.3.6.tar.gz/download
解压,并重命名:postfixadmin,复制到/var/www/html
sudo cp -rf /home/pandy/下载/postfixadmin /var/www/html

修改postfixadmin配置文件:
sudo gedit /var/www/html/postfixadmin/config.inc.php
------------
$CONF['configured'] = true;
$CONF['default_language'] = 'cn';
$CONF['database_type'] = 'mysql';
$CONF['database_host'] = 'localhost';
$CONF['database_user'] = 'admin';
$CONF['database_password'] = '123123';
$CONF['database_name'] = 'mail';
$CONF['admin_email'] = 'admin@pandy8.com';
$CONF['encrypt'] = 'dovecot:CRAM-MD5';
$CONF['dovecotpw'] = "/usr/bin/doveadm pw";
$CONF['domain_path'] = 'YES';
$CONF['domain_in_mailbox'] = 'NO';
$CONF['aliases'] = '1000';
$CONF['mailboxes'] = '1000';
$CONF['maxquota'] = '1000';
$CONF['fetchmail'] = 'NO';
$CONF['emailcheck_resolve_domain']='NO';
$CONF['quota'] = 'YES';
$CONF['used_quotas'] = 'YES';
$CONF['new_quota_table'] = 'YES';


进入postfixadmin:
http://127.0.0.1/postfixadmin/setup.php
输入:admin / admin, generate password hash, 跳转到第二部, 得到一个hash code,
复制这个code,并修改:sudo gedit /var/www/html/postfixadmin/config.inc.php
$CONF['setup_password'] = 'ae3e1cb27c62fae6c43dc1fd84853207:03bf21e651640880b910317a27fdb205fe8949fa'; //这个值是根据你的输入变化的
然后继续其他设定,注意,先不创建管理员账户,以后再创建。


postfixadmin
=================================
postfxiadmin不能自动创建目录,增加自动建立目录的功能
建立创建虚拟邮箱脚本,脚本名称 /usr/local/bin/maildir-creation.sh ,脚本内容如下:
sudo gedit /usr/local/bin/maildir-creation.sh
--------------------------------------------
#!/bin/bash
HOME_DIR="/var/vmail"
USER_NAME="vmail"
GROUP_NAME="vmail"
if [ ! -d ${HOME_DIR}/$1 ] ; then
    mkdir ${HOME_DIR}/$1
    chown -R ${USER_NAME}.${GROUP_NAME} ${HOME_DIR}/$1
fi
mkdir ${HOME_DIR}/$1/$2
chown -R ${USER_NAME}.${GROUP_NAME} ${HOME_DIR}/$1/$2


建立删除虚拟邮箱脚本,脚本名称 /usr/local/bin/maildir-deletion.sh ,脚本内容如下:
sudo gedit /usr/local/bin/maildir-deletion.sh
----------------------------------------------
#!/bin/bash
#
# vmta ALL = NOPASSWD: /usr/local/bin/maildir-deletion.sh
#
if [ $# -ne 2 ] ; then
  exit 127
fi
DOMAIN="$1"
USER="$2"
HOME_DIR="/var/vmail"
USER_DIR="${HOME_DIR}/${DOMAIN}/${USER}"
TRASH_DIR="${HOME_DIR}/deleted-maildirs"
DATE=`date "+%Y%m%d_%H%M%S"`
if [ ! -d "${TRASH_DIR}/${DOMAIN}" ] ; then
    mkdir -p "${TRASH_DIR}/${DOMAIN}"
fi
if [ -d "${USER_DIR}" ] ; then
    mv ${USER_DIR} ${TRASH_DIR}/${DOMAIN}/${USER}-${DATE}
fi


建立删除目录
sudo mkdir /var/vmail/deleted-maildirs
sudo chown -R vmail.vmail /var/vmail/deleted-maildirs/


赋予脚本可执行权限
sudo chmod 750 /usr/local/bin/maildir-*
sudo chown vmail.vmail /usr/local/bin/maildir-*


配置sudo
在 /etc/sudoers 增加一行
sudo vim /etc/sudoers
----------------------------
vmail ALL = NOPASSWD: /usr/local/bin/maildir-creation.sh
vmail ALL = NOPASSWD: /usr/local/bin/maildir-deletion.sh
注释掉下面内容
#Defaults    requiretty
esc , :wq!, 强制保存


修改postfixadmin的相关文件
修改create-mailbox.php 文件,229行内容应该是:
sudo gedit /var/www/html/postfixadmin/create-mailbox.php
db_log ($SESSID_USERNAME, $fDomain, 'create_mailbox', "$fUsername");
在该行前面增加下面一行:
system("sudo /usr/local/bin/maildir-creation.sh $fDomain ".$_POST['fUsername']);

修改delete.php 文件,146行内容应该是:
sudo gedit /var/www/html/postfixadmin/delete.php
db_log ($SESSID_USERNAME, $fDomain, 'delete_mailbox', $fDelete);
在该行下面增加下面4行:
$userarray=explode("@",$fDelete);
$user=$userarray[0];
$domain=$userarray[1];
system("sudo /usr/local/bin/maildir-deletion.sh $domain $user");




4、配置Postfix
一些属性意义,可以参考:http://www.centospub.com/make/postfix_smtp.html
=========================================
修改/etc/postfix/main.cf文件
sudo gedit /etc/postfix/main.cf
基本配置
---------------------------------------以下修改
myhostname = bogon  //这个是hostname命令得到的
mydomain = pandy8.com
myorigin = $mydomain
inet_interfaces = all
mydestination = localhost    //是否需要修改成其他?无法收外网的信,即使有MX记录
#mydestination = $myhostname, localhost.$mydomain, localhost, $mydomain  //这个要注释掉?,否则出现unknown user错误。
mynetworks_style = host


虚拟域名配置
---------------------------------------以下增加
#=======================================================================
# ADDRESS REDIRECTION (VIRTUAL DOMAIN)
#
# The VIRTUAL_README document gives information about the many forms
# of domain hosting that Postfix supports.
# See: http://www.howtoforge.com/virtual-users-domains-postfix-courier-mysql-squirrelmail-ubuntu8.04-p2
# The follwing lines connect Postfix with the MySQL database that contains information about
# the virtual users/accounts hosted. See proxymap(8) virtual(5) and mysql_table(5)
#
virtual_mailbox_domains = proxy:mysql:/etc/postfix/mysql_virtual_domains_maps.cf
#
virtual_alias_maps = proxy:mysql:/etc/postfix/mysql_virtual_alias_maps.cf
#
virtual_mailbox_maps = proxy:mysql:/etc/postfix/mysql_virtual_mailbox_maps.cf
#
# Additional for quota support
virtual_create_maildirsize = yes
virtual_mailbox_extended = yes
virtual_mailbox_limit_maps = mysql:/etc/postfix/mysql_virtual_mailbox_limit_maps.cf
virtual_mailbox_limit_override = yes
virtual_maildir_limit_message = Sorry, this user has exceeded their disk space quota, please try again later.
virtual_overquota_bounce = yes
#
#Specify the user/group that owns the mail folders. I'm not sure if this is strictly necessary when using Dovecot's LDA.
virtual_uid_maps = static:2000
virtual_gid_maps = static:2000
#
#Specifies which tables proxymap can read: http://www.postfix.org/postconf.5.html#proxy_read_maps
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


SMTP加密设定
---------------------------------------
#=======================================================================
#SASL SUPPORT FOR CLIENTS
#
# The following options set parameters needed by Postfix to enable
# SMTP AUTH support using Dovecot's SASL component for authentication of mail clients.
# See: /usr/share/doc/postfix-2.3.3/README_FILES/SASL_README - http://www.postfix.org/SASL_README.html
# And /usr/share/doc/dovecot-1.0.7/wiki/HowTo.PostfixAndDovecotSASL.txt - http://wiki.dovecot.org/HowTo/PostfixAndDovecotSASL
#
# Turns on sasl authorization
smtpd_sasl_auth_enable = yes
#
#Use dovecot for authentication
smtpd_sasl_type = dovecot
#
# Path to UNIX socket for SASL
smtpd_sasl_path = /var/run/dovecot/auth-client
#
#Disable anonymous login. We don't want to run an open relay for spammers.
smtpd_sasl_security_options = noanonymous
#
#Adds support for email software that doesn't follow RFC 4954.
#This includes most versions of Microsoft Outlook before 2007.
broken_sasl_auth_clients = yes
#
smtpd_recipient_restrictions =  permit_sasl_authenticated, permit_mynetworks, reject_unauth_destination


使用Dovecot做为投递
---------------------------------------
#=======================================================================
# TRANSPORT MAP
#
virtual_transport = dovecot
dovecot_destination_recipient_limit = 1



修改master.cf文件
sudo gedit /etc/postfix/master.cf
在底部增加
---------------------------------------
dovecot   unix  -       n       n       -       -       pipe
  flags=DRhu user=vmail:vmail argv=/usr/libexec/dovecot/dovecot-lda -f ${sender} -d ${recipient}


创建Mysql脚本
==================================
sudo gedit /etc/postfix/mysql_virtual_domains_maps.cf
---------------------------------------
user = admin
password = 123123
hosts = localhost
dbname = mail
query = SELECT domain FROM domain WHERE domain='%s' AND active = '1'
#optional query to use when relaying for backup MX
#query = SELECT domain FROM domain WHERE domain='%s' AND backupmx = '0' AND active = '1'

sudo gedit /etc/postfix/mysql_virtual_alias_maps.cf
----------------------------
user = admin
password = 123123
hosts = localhost
dbname = mail
query = SELECT goto FROM alias WHERE address='%s' AND active = '1'

sudo gedit /etc/postfix/mysql_virtual_mailbox_maps.cf
-----------------------------
user = admin
password = 123123
hosts = localhost
dbname = mail
query = SELECT CONCAT(domain,'/',maildir) FROM mailbox WHERE username='%s' AND active = '1'

sudo gedit /etc/postfix/mysql_virtual_mailbox_limit_maps.cf
--------------------------------------
user = admin
password = 123123
hosts = localhost
dbname = mail
query = SELECT quota FROM mailbox WHERE username='%s' AND active = '1'


5、配置Dovecot
================================================
因为配置文件比较分散,我把需要修改的配置文件的内容列出来
sudo gedit /etc/dovecot/dovecot.conf
---------------------------------
protocols = imap pop3
listen = *
dict {
  quota = mysql:/etc/dovecot/dovecot-dict-sql.conf.ext
}
!include conf.d/*.conf

sudo gedit /etc/dovecot/conf.d/10-auth.conf
---------------------------------
disable_plaintext_auth = no
auth_mechanisms = plain login cram-md5
!include auth-sql.conf.ext

sudo gedit /etc/dovecot/conf.d/10-mail.conf
--------------------------------
mail_location = maildir:%hMaildir
mbox_write_locks = fcntl

sudo gedit /etc/dovecot/conf.d/10-master.conf
---------------------------
service imap-login {
  inet_listener imap {
  }
  inet_listener imaps {
  }
}
service pop3-login {
  inet_listener pop3 {
  }
  inet_listener pop3s {
  }
}
service lmtp {
  unix_listener lmtp {
  }
}
service imap {
}
service pop3 {
}
service auth {
  unix_listener auth-userdb {
    mode = 0600
    user = vmail
    group = vmail
  }
  unix_listener auth-client {
    mode = 0600
    user = postfix
    group = postfix
  }
}
service auth-worker {
}
service dict {
  unix_listener dict {
    mode = 0600
    user = vmail
    group = vmail
  }
}

sudo gedit /etc/dovecot/conf.d/15-lda.conf
---------------------
protocol lda {
  mail_plugins = quota
  postmaster_address = admin@pandy8.com
}

sudo gedit /etc/dovecot/conf.d/20-imap.conf
-----------------------------
protocol imap {
        mail_plugins = quota imap_quota
}

sudo gedit /etc/dovecot/conf.d/20-pop3.conf

------------------------------
protocol pop3 {
  pop3_uidl_format = %08Xu%08Xv
  mail_plugins = quota
}

sudo gedit /etc/dovecot/conf.d/90-quota.conf
----------------------------
plugin {
  quota_rule = *:storage=1G
}
plugin {
}
plugin {
  quota = dict:User quota::proxy::quota
}
plugin {
}

sudo gedit /etc/dovecot/dovecot-sql.conf.ext
--------------------------
driver = mysql
connect = host=localhost dbname=mail user=admin password=123123
default_pass_scheme = CRAM-MD5
user_query = SELECT CONCAT('/var/vmail/', maildir) AS home, 2000 AS uid, 2000 AS gid, CONCAT('*:bytes=', quota) as quota_rule FROM mailbox WHERE username = '%u' AND active='1'
password_query = SELECT username AS user, password, CONCAT('/var/vmail/', maildir) AS userdb_home, 2000 AS userdb_uid, 2000 AS userdb_gid, CONCAT('*:bytes=', quota) as userdb_quota_rule FROM mailbox WHERE username = '%u' AND active='1'

sudo gedit /etc/dovecot/dovecot-dict-sql.conf.ext
-----------------------------
connect = host=localhost dbname=mail user=admin password=123123
map {
  pattern = priv/quota/storage
  table = quota2
  username_field = username
  value_field = bytes
}
map {
  pattern = priv/quota/messages
  table = quota2
  username_field = username
  value_field = messages
}

sudo gedit /etc/pam.d/dovecot
-------------------------
#%PAM-1.0
#auth       required     pam_nologin.so
#auth       include      password-auth
#account    include      password-auth
#session    include      password-auth
auth    required        pam_unix.so nullok
account required        pam_unix.so

重启CentOS:reboot

测试监听:
netstat -tlunp | grep ':25'
netstat -tlunp | grep ':110'
sudo postfix check //没返回任何信息,就是最好
sudo tail 0f /var/log/maillog //查看maillog

再次进入:http://127.0.0.1/postfixadmin/setup.php
输入:admin, admin@pandy8.com, admin, admin
显示:新增管理员成功!,(admin@pandy8.com), 增加管理员成功;
进入:http://127.0.0.1/postfixadmin/login.php
使用管理员和密码进入:admin@pandy8.com/admin,
增加一个:pandy8.com的域名;
增加一个邮箱:test@pandy8.com


测试发件:
[pandy@localhost ~]$ telnet localhost 25
Trying ::1...
Connected to localhost.
Escape character is '^]'.
220 bogon ESMTP Postfix
ehlo test@pandy8.com<---输入内容
250-bogon
250-PIPELINING
250-SIZE 10240000
250-VRFY
250-ETRN
250-AUTH PLAIN LOGIN CRAM-MD5
250-AUTH=PLAIN LOGIN CRAM-MD5
250-ENHANCEDSTATUSCODES
250-8BITMIME
250 DSN
quit



测试收件:
[pandy@bogon ~]$ telnet localhost 110
Trying ::1...
telnet: connect to address ::1: Connection refused
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
+OK Dovecot ready.
user test@pandy8.com<---输入内容
+OK
pass test<---输入内容
+OK Logged in.
quit<---输入内容
+OK Logging out.
Connection closed by foreign host.


安装roundcubemail
===================================
下载位置,可能要跳墙才能下载
http://superb-dca2.dl.sourceforge.net/project/roundcubemail/roundcubemail/0.9.1/roundcubemail-0.9.1.tar.gz
解压,重新命名:roundcubemail,并复制到html文件夹
sudo cp -rf /home/pandy/下载/roundcubemail /var/www/html/

建立roundcubemail数据库和Mysql用户
mysql -h localhost -uroot -p
mysql> CREATE DATABASE roundcubemail;
mysql> GRANT ALL PRIVILEGES ON roundcubemail.* TO roundcubemail@localhost IDENTIFIED BY 'pa5swd';
mysql> flush privileges;

安装mysql工具,来执行sql:
下载位置:http://dev.mysql.com/downloads/tools/workbench/
或者:http://download.softagency.net/MySQL/Downloads/MySQLGUITools/
使用这个工具执行:roundcubemail/SQL/mysql.initial.sql
注意,是使用roundcubemail账户和密码进去执行

配置Roundcubemail
配置数据库配置文件
cd /var/www/html/roundcubemail/config/
sudo cp db.inc.php.dist db.inc.php
sudo gedit db.inc.php
如下修改:
$rcmail_config['db_dsnw'] = 'mysql://roundcubemail:pa5swd@localhost/roundcubemail';

配置主配置文件
sudo cp main.inc.php.dist main.inc.php
sudo gedit main.inc.php
如下修改:
$rcmail_config['default_host'] = 'localhost';
$rcmail_config['username_domain'] = 'pandy8.com';
$rcmail_config['mail_domain'] = 'mail.pandy8.com';
$rcmail_config['smtp_server'] = 'localhost';
$rcmail_config['product_name'] = 'RH Webmail';

重新启动httpd服务:
sudo service httpd restart;

进入:http://127.0.0.1/roundcubemail/
使用上面创建的:test@pandy8.com/test进入

查看收件箱,就能看到创建帐号自动发送的邮件,如果没有,那么到postfixadmin里面去尝试发送一个,就看见了。


Roundcube邮件系统的插件http://trac.roundcube.net/wiki/Plugin_Repository
配置managesieve插件, 提供过滤器,假期回复
sudo yum -y install dovecot-pigeonhole

配置dovecot配置文件
修改/etc/dovecot/dovecot.conf文件,做如下修改:
sudo gedit /etc/dovecot/dovecot.conf
protocols = pop3 imap sieve

修改/etc/dovecot/conf.d/15-lda.conf文件,做如下修改:
sudo gedit /etc/dovecot/conf.d/15-lda.conf
mail_plugins = quota sieve

重新启动dovecot
sudo service dovecot restart

Dovecot监听4190端口
netstat -tunlp | grep 4190
tcp        0      0 0.0.0.0:4190                0.0.0.0:*                   LISTEN      2188/dovecot

managesieve配置文件修改,将模板复制成config.inc.php,做如下修改:
[root@mail config]#cd /var/www/html/roundcubemail/plugins/managesieve/
[root@mail managesieve]# cp config.inc.php.dist config.inc.php
[root@mail managesieve]# gedit config.inc.php
修改以下内容:
$rcmail_config['managesieve_port'] = 4190;

使插件生效
修改/var/www/html/config/main.inc.php文件
sudo gedit /var/www/html/roundcubemail/config/main.inc.php
修改以下内容:
$rcmail_config['plugins'] = array('managesieve');

测试插件
Managesieve界面

更多插件的配置见
Roundcube Webmail 多域及插件配置篇:http://blog.dvxj.com/pandola/roundcube-webmail-plugins.html
$rcmail_config['plugins'] = array('managesieve','password','filesystem_attachments', 'emoticons', 'example_addressbook', 'message_highlight','jqueryui','globaladdressbook','userinfo','markasjunk','enigma','vcard_attachments','help');
加了6个插件,为啥是6个,因为那个jqueryui是其他插件要用的脚本,所以具体插件数目是6个,array圆括号内的参数,单引号引起来的,比如'password',引号内的内容,一定是和plugins目录中插件目录名一致,这样Roundcube才会根据配置,加载相应的插件。
globaladdressbook:全局地址簿,这个功能其实不错,可以让域管理员统一提前配置好公司所有人的邮件地址,这样大家发邮件的时候就可以使用现成的了。当然,这个不影响每个用户自己私人的地址簿,是分开的。
sudo cp -rf /home/pandy/下载/global-address-book /var/www/html/roundcubemail/plugins/
compose_addressbook:是写邮件时,可以通过点击一个按钮,弹出窗口调出地址簿,让你选择收件人,抄送、密送等邮件地址;
sudo cp -rf /home/pandy/下载/compose_addressbook /var/www/html/roundcubemail/plugins/
message_highlight: 高亮显示
sudo cp -rf /home/pandy/下载/message_highlight /var/www/html/roundcubemail/plugins/
注意,这些名字在下载后是有修改过的,有些没配置成功,那就像钓@鱼@岛问题一样,留给后人。


皮肤:
sudo gedit /var/www/html/roundcubemail/config/main.inc.php
$rcmail_config['skin'] = 'larry'; //默认皮肤
$rcmail_config['skin'] = 'classic';








修改端口:
sudo gedit /etc/dovecot/dovecot.conf
里面有说明:
# If you want to specify ports for each service, you will need to configure
# these settings inside the protocol imap/pop3 { ... } section, so you can
# specify different ports for IMAP/POP3. For example:
# protocol imap {
# listen = *:10143
# ssl_listen = *:10943
# ..
# }
# protocol pop3 {
# listen = *:10100
# ..
# }


问题:
1. dovecot测试 -ERR Authentication failed
http://hi.baidu.com/lijunyi0198/item/977522993c76838a591461eb

2. Connection closed by foreign host
确保运行dovecot服务,sudo chkconfig postfix on , service dovecot restart;
http://www.pooy.net/connection-closed-foreign-host.html
造成这个原 因是因为原来连接到SSHD服务器进程的22端口,当你的客户端突然断开时,服务器端的TCP连接就处于一个半打开状态。当下一次同一客户机再次建立 TCP连接时,服务器检测到这个半打开的TCP连接,并向客户机回传一个置位RST的TCP报文,客户机就会显示connection closed by foreign host。
这是TCP协议本身的一个保护措施,并不是什么错误,你只要再重新连接服务器就能连上。
我用的是wifi,然后登录路由之后,断网,自动的重新链接即可了!

3. Mailbox doesn't exist: INBOX
  vim /etc/dovecot/conf.d/10-mail.conf
  mail_location = maildir:%hMaildir, 否则会报这个错误

4.解决httpd: Could not reliably determine the server's fully qualified domain name, using 127.0.0.1 for ServerName
http://hi.baidu.com/luocs224/item/ec12e43f04c77f677c034b83
配置文件:/etc/httpd/conf/httpd.conf

5. 日志文件:sudo gedit /var/log/maillog

6. 收信不成功,看后台日志:
Error: user test@pandy8.com: Initialization failed: Initializing mail storage from mail_location setting failed: mkdir(/var/vmail/pandy8.com/test/Maildir) failed: Permission denied (euid=2000(vmail) egid=2000(vmail) missing +w perm: /var/vmail/pandy8.com, euid is not dir owner)

7. 收信不成功,看后台日志:
postfix/local[2670]: 74CD9281454: to=<test@pandy8.com>, relay=local, delay=0.33, delays=0.11/0.17/0/0.05, dsn=5.1.1, status=bounced (unknown user: "test")
http://stackoverflow.com/questions/18377813/postfix-status-bounced-unknown-user-myuser
mydestination = localhost  //使用这个
#mydestination = $myhostname, localhost.$mydomain, localhost, $mydomain //注释掉这个。


8. Foxmail链接
http://www.extmail.net/forum/viewthread.php?tid=24693&page=1
改成
inet_interfaces = all
mynetworks = 127.0.0.1,192.168.1.0/24
客户端===>让软件自动寻找也可以
pop.pandy8.com、pop3.pandy8.com
smtp.pandy8.com
sudo chkconfig dovecot on
sudo chkconfig httpd on
sudo chkconfig mysqld on
sudo service postfix restart
sudo service dovecot restart
sudo service httpd restart
sudo service mysqld restart [/color]
注意:以上自动开机运行和启动服务很重要,否则可能会碰到乱七八糟的问题

创建一个vmail用户,用作管理虚拟邮箱的文件夹
sudo useradd -u 2000 -d /var/vmail -m -s /sbin/nologin vmail

创建mail数据库和账户
mysqladmin -uroot password 'root'
mysql -h localhost -uroot -p
mysql> GRANT ALL PRIVILEGES ON mail.* TO root@localhost IDENTIFIED BY 'root';
mysql> create database mail;
mysql> GRANT ALL PRIVILEGES ON mail.* TO admin@"localhost" IDENTIFIED BY '123123' WITH GRANT OPTION;
mysql> flush privileges;

下载postfixadmin:
http://sourceforge.net/projects/postfixadmin/files/postfixadmin/postfixadmin-2.3.6/postfixadmin-2.3.6.tar.gz/download
解压,并重命名:postfixadmin,复制到/var/www/html
sudo cp -rf /home/pandy/下载/postfixadmin /var/www/html

修改postfixadmin配置文件:
sudo gedit /var/www/html/postfixadmin/config.inc.php
------------
$CONF['configured'] = true;
$CONF['default_language'] = 'cn';
$CONF['database_type'] = 'mysql';
$CONF['database_host'] = 'localhost';
$CONF['database_user'] = 'admin';
$CONF['database_password'] = '123123';
$CONF['database_name'] = 'mail';
$CONF['admin_email'] = 'admin@pandy8.com';
$CONF['encrypt'] = 'dovecot:CRAM-MD5';
$CONF['dovecotpw'] = "/usr/bin/doveadm pw";
$CONF['domain_path'] = 'YES';
$CONF['domain_in_mailbox'] = 'NO';
$CONF['aliases'] = '1000';
$CONF['mailboxes'] = '1000';
$CONF['maxquota'] = '1000';
$CONF['fetchmail'] = 'NO';
$CONF['quota'] = 'YES';
$CONF['used_quotas'] = 'YES';
$CONF['new_quota_table'] = 'YES';


进入postfixadmin:
http://127.0.0.1/postfixadmin/setup.php
输入:admin / admin, generate password hash, 跳转到第二部, 得到一个hash code,
复制这个code,并修改:sudo gedit /var/www/html/postfixadmin/config.inc.php
$CONF['setup_password'] = 'ae3e1cb27c62fae6c43dc1fd84853207:03bf21e651640880b910317a27fdb205fe8949fa'; //这个值是根据你的输入变化的
然后继续其他设定,注意,先不创建管理员账户,以后再创建。


postfixadmin
=================================
postfxiadmin不能自动创建目录,增加自动建立目录的功能
建立创建虚拟邮箱脚本,脚本名称 /usr/local/bin/maildir-creation.sh ,脚本内容如下:
sudo gedit /usr/local/bin/maildir-creation.sh
--------------------------------------------
#!/bin/bash
HOME_DIR="/var/vmail"
USER_NAME="vmail"
GROUP_NAME="vmail"
if [ ! -d ${HOME_DIR}/$1 ] ; then
    mkdir ${HOME_DIR}/$1
    chown -R ${USER_NAME}.${GROUP_NAME} ${HOME_DIR}/$1
fi
mkdir ${HOME_DIR}/$1/$2
chown -R ${USER_NAME}.${GROUP_NAME} ${HOME_DIR}/$1/$2


建立删除虚拟邮箱脚本,脚本名称 /usr/local/bin/maildir-deletion.sh ,脚本内容如下:
sudo gedit /usr/local/bin/maildir-deletion.sh
----------------------------------------------
#!/bin/bash
#
# vmta ALL = NOPASSWD: /usr/local/bin/maildir-deletion.sh
#
if [ $# -ne 2 ] ; then
  exit 127
fi
DOMAIN="$1"
USER="$2"
HOME_DIR="/var/vmail"
USER_DIR="${HOME_DIR}/${DOMAIN}/${USER}"
TRASH_DIR="${HOME_DIR}/deleted-maildirs"
DATE=`date "+%Y%m%d_%H%M%S"`
if [ ! -d "${TRASH_DIR}/${DOMAIN}" ] ; then
    mkdir -p "${TRASH_DIR}/${DOMAIN}"
fi
if [ -d "${USER_DIR}" ] ; then
    mv ${USER_DIR} ${TRASH_DIR}/${DOMAIN}/${USER}-${DATE}
fi


建立删除目录
sudo mkdir /var/vmail/deleted-maildirs
sudo chown -R vmail.vmail /var/vmail/deleted-maildirs/


赋予脚本可执行权限
sudo chmod 750 /usr/local/bin/maildir-*
sudo chown vmail.vmail /usr/local/bin/maildir-*


配置sudo
在 /etc/sudoers 增加一行
sudo vim /etc/sudoers
----------------------------
vmail ALL = NOPASSWD: /usr/local/bin/maildir-creation.sh
vmail ALL = NOPASSWD: /usr/local/bin/maildir-deletion.sh
注释掉下面内容
#Defaults    requiretty
esc , :wq!, 强制保存


修改postfixadmin的相关文件
修改create-mailbox.php 文件,229行内容应该是:
sudo gedit /var/www/html/postfixadmin/create-mailbox.php
db_log ($SESSID_USERNAME, $fDomain, 'create_mailbox', "$fUsername");
在该行前面增加下面一行:
system("sudo /usr/local/bin/maildir-creation.sh $fDomain ".$_POST['fUsername']);

修改delete.php 文件,146行内容应该是:
sudo gedit /var/www/html/postfixadmin/delete.php
db_log ($SESSID_USERNAME, $fDomain, 'delete_mailbox', $fDelete);
在该行下面增加下面4行:
$userarray=explode("@",$fDelete);
$user=$userarray[0];
$domain=$userarray[1];
system("sudo /usr/local/bin/maildir-deletion.sh $domain $user");




4、配置Postfix
一些属性意义,可以参考:http://www.centospub.com/make/postfix_smtp.html
=========================================
修改/etc/postfix/main.cf文件
sudo gedit /etc/postfix/main.cf
基本配置
---------------------------------------以下修改
myhostname = bogon  //这个是hostname命令得到的
mydomain = pandy8.com
myorigin = $mydomain
inet_interfaces = all
mydestination = localhost    //是否需要修改成其他?无法收外网的信,即使有MX记录
#mydestination = $myhostname, localhost.$mydomain, localhost, $mydomain  //这个要注释掉?,否则出现unknown user错误。
mynetworks_style = host


虚拟域名配置
---------------------------------------以下增加
#=======================================================================
# ADDRESS REDIRECTION (VIRTUAL DOMAIN)
#
# The VIRTUAL_README document gives information about the many forms
# of domain hosting that Postfix supports.
# See: http://www.howtoforge.com/virtual-users-domains-postfix-courier-mysql-squirrelmail-ubuntu8.04-p2
# The follwing lines connect Postfix with the MySQL database that contains information about
# the virtual users/accounts hosted. See proxymap(8) virtual(5) and mysql_table(5)
#
virtual_mailbox_domains = proxy:mysql:/etc/postfix/mysql_virtual_domains_maps.cf
#
virtual_alias_maps = proxy:mysql:/etc/postfix/mysql_virtual_alias_maps.cf
#
virtual_mailbox_maps = proxy:mysql:/etc/postfix/mysql_virtual_mailbox_maps.cf
#
# Additional for quota support
virtual_create_maildirsize = yes
virtual_mailbox_extended = yes
virtual_mailbox_limit_maps = mysql:/etc/postfix/mysql_virtual_mailbox_limit_maps.cf
virtual_mailbox_limit_override = yes
virtual_maildir_limit_message = Sorry, this user has exceeded their disk space quota, please try again later.
virtual_overquota_bounce = yes
#
#Specify the user/group that owns the mail folders. I'm not sure if this is strictly necessary when using Dovecot's LDA.
virtual_uid_maps = static:2000
virtual_gid_maps = static:2000
#
#Specifies which tables proxymap can read: http://www.postfix.org/postconf.5.html#proxy_read_maps
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


SMTP加密设定
---------------------------------------
#=======================================================================
#SASL SUPPORT FOR CLIENTS
#
# The following options set parameters needed by Postfix to enable
# SMTP AUTH support using Dovecot's SASL component for authentication of mail clients.
# See: /usr/share/doc/postfix-2.3.3/README_FILES/SASL_README - http://www.postfix.org/SASL_README.html
# And /usr/share/doc/dovecot-1.0.7/wiki/HowTo.PostfixAndDovecotSASL.txt - http://wiki.dovecot.org/HowTo/PostfixAndDovecotSASL
#
# Turns on sasl authorization
smtpd_sasl_auth_enable = yes
#
#Use dovecot for authentication
smtpd_sasl_type = dovecot
#
# Path to UNIX socket for SASL
smtpd_sasl_path = /var/run/dovecot/auth-client
#
#Disable anonymous login. We don't want to run an open relay for spammers.
smtpd_sasl_security_options = noanonymous
#
#Adds support for email software that doesn't follow RFC 4954.
#This includes most versions of Microsoft Outlook before 2007.
broken_sasl_auth_clients = yes
#
smtpd_recipient_restrictions =  permit_sasl_authenticated, permit_mynetworks, reject_unauth_destination


使用Dovecot做为投递
---------------------------------------
#=======================================================================
# TRANSPORT MAP
#
virtual_transport = dovecot
dovecot_destination_recipient_limit = 1



修改master.cf文件
sudo gedit /etc/postfix/master.cf
在底部增加
---------------------------------------
dovecot   unix  -       n       n       -       -       pipe
  flags=DRhu user=vmail:vmail argv=/usr/libexec/dovecot/dovecot-lda -f ${sender} -d ${recipient}


创建Mysql脚本
==================================
sudo gedit /etc/postfix/mysql_virtual_domains_maps.cf
---------------------------------------
user = admin
password = 123123
hosts = localhost
dbname = mail
query = SELECT domain FROM domain WHERE domain='%s' AND active = '1'
#optional query to use when relaying for backup MX
#query = SELECT domain FROM domain WHERE domain='%s' AND backupmx = '0' AND active = '1'

sudo gedit /etc/postfix/mysql_virtual_alias_maps.cf
----------------------------
user = admin
password = 123123
hosts = localhost
dbname = mail
query = SELECT goto FROM alias WHERE address='%s' AND active = '1'

sudo gedit /etc/postfix/mysql_virtual_mailbox_maps.cf
-----------------------------
user = admin
password = 123123
hosts = localhost
dbname = mail
query = SELECT CONCAT(domain,'/',maildir) FROM mailbox WHERE username='%s' AND active = '1'

sudo gedit /etc/postfix/mysql_virtual_mailbox_limit_maps.cf
--------------------------------------
user = admin
password = 123123
hosts = localhost
dbname = mail
query = SELECT quota FROM mailbox WHERE username='%s' AND active = '1'


5、配置Dovecot
================================================
因为配置文件比较分散,我把需要修改的配置文件的内容列出来
sudo gedit /etc/dovecot/dovecot.conf
---------------------------------
protocols = imap pop3
listen = *
dict {
  quota = mysql:/etc/dovecot/dovecot-dict-sql.conf.ext
}
!include conf.d/*.conf

sudo gedit /etc/dovecot/conf.d/10-auth.conf
---------------------------------
disable_plaintext_auth = no
auth_mechanisms = plain login cram-md5
!include auth-sql.conf.ext

sudo gedit /etc/dovecot/conf.d/10-mail.conf
--------------------------------
mail_location = maildir:%hMaildir
mbox_write_locks = fcntl

sudo gedit /etc/dovecot/conf.d/10-master.conf
---------------------------
service imap-login {
  inet_listener imap {
  }
  inet_listener imaps {
  }
}
service pop3-login {
  inet_listener pop3 {
  }
  inet_listener pop3s {
  }
}
service lmtp {
  unix_listener lmtp {
  }
}
service imap {
}
service pop3 {
}
service auth {
  unix_listener auth-userdb {
    mode = 0600
    user = vmail
    group = vmail
  }
  unix_listener auth-client {
    mode = 0600
    user = postfix
    group = postfix
  }
}
service auth-worker {
}
service dict {
  unix_listener dict {
    mode = 0600
    user = vmail
    group = vmail
  }
}

sudo gedit /etc/dovecot/conf.d/15-lda.conf
---------------------
protocol lda {
  mail_plugins = quota
  postmaster_address = admin@pandy8.com
}

sudo gedit /etc/dovecot/conf.d/20-imap.conf
-----------------------------
protocol imap {
        mail_plugins = quota imap_quota
}

sudo gedit /etc/dovecot/conf.d/20-pop3.conf

------------------------------
protocol pop3 {
  pop3_uidl_format = %08Xu%08Xv
  mail_plugins = quota
}

sudo gedit /etc/dovecot/conf.d/90-quota.conf
----------------------------
plugin {
  quota_rule = *:storage=1G
}
plugin {
}
plugin {
  quota = dict:User quota::proxy::quota
}
plugin {
}

sudo gedit /etc/dovecot/dovecot-sql.conf.ext
--------------------------
driver = mysql
connect = host=localhost dbname=mail user=admin password=123123
default_pass_scheme = CRAM-MD5
user_query = SELECT CONCAT('/var/vmail/', maildir) AS home, 2000 AS uid, 2000 AS gid, CONCAT('*:bytes=', quota) as quota_rule FROM mailbox WHERE username = '%u' AND active='1'
password_query = SELECT username AS user, password, CONCAT('/var/vmail/', maildir) AS userdb_home, 2000 AS userdb_uid, 2000 AS userdb_gid, CONCAT('*:bytes=', quota) as userdb_quota_rule FROM mailbox WHERE username = '%u' AND active='1'

sudo gedit /etc/dovecot/dovecot-dict-sql.conf.ext
-----------------------------
connect = host=localhost dbname=mail user=admin password=123123
map {
  pattern = priv/quota/storage
  table = quota2
  username_field = username
  value_field = bytes
}
map {
  pattern = priv/quota/messages
  table = quota2
  username_field = username
  value_field = messages
}

sudo gedit /etc/pam.d/dovecot
-------------------------
#%PAM-1.0
#auth       required     pam_nologin.so
#auth       include      password-auth
#account    include      password-auth
#session    include      password-auth
auth    required        pam_unix.so nullok
account required        pam_unix.so

重启CentOS:reboot

测试监听:
netstat -tlunp | grep ':25'
netstat -tlunp | grep ':110'
sudo postfix check //没返回任何信息,就是最好
sudo tail 0f /var/log/maillog //查看maillog

再次进入:http://127.0.0.1/postfixadmin/setup.php
输入:admin, admin@pandy8.com, admin, admin
显示:新增管理员成功!,(admin@pandy8.com), 增加管理员成功;
进入:http://127.0.0.1/postfixadmin/login.php
使用管理员和密码进入:admin@pandy8.com/admin,
增加一个:pandy8.com的域名;
增加一个邮箱:test@pandy8.com


测试发件:
[pandy@localhost ~]$ telnet localhost 25
Trying ::1...
Connected to localhost.
Escape character is '^]'.
220 bogon ESMTP Postfix
ehlo test@pandy8.com<---输入内容
250-bogon
250-PIPELINING
250-SIZE 10240000
250-VRFY
250-ETRN
250-AUTH PLAIN LOGIN CRAM-MD5
250-AUTH=PLAIN LOGIN CRAM-MD5
250-ENHANCEDSTATUSCODES
250-8BITMIME
250 DSN
quit



测试收件:
[pandy@bogon ~]$ telnet localhost 110
Trying ::1...
telnet: connect to address ::1: Connection refused
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
+OK Dovecot ready.
user test@pandy8.com<---输入内容
+OK
pass test<---输入内容
+OK Logged in.
quit<---输入内容
+OK Logging out.
Connection closed by foreign host.


安装roundcubemail
===================================
下载位置,可能要跳墙才能下载
http://superb-dca2.dl.sourceforge.net/project/roundcubemail/roundcubemail/0.9.1/roundcubemail-0.9.1.tar.gz
解压,重新命名:roundcubemail,并复制到html文件夹
sudo cp -rf /home/pandy/下载/roundcubemail /var/www/html/

建立roundcubemail数据库和Mysql用户
mysql -h localhost -uroot -p
mysql> CREATE DATABASE roundcubemail;
mysql> GRANT ALL PRIVILEGES ON roundcubemail.* TO roundcubemail@localhost IDENTIFIED BY 'pa5swd';
mysql> flush privileges;

安装mysql工具,来执行sql:
下载位置:http://dev.mysql.com/downloads/tools/workbench/
或者:http://download.softagency.net/MySQL/Downloads/MySQLGUITools/
使用这个工具执行:roundcubemail/SQL/mysql.initial.sql
注意,是使用roundcubemail账户和密码进去执行

配置Roundcubemail
配置数据库配置文件
cd /var/www/html/roundcubemail/config/
sudo cp db.inc.php.dist db.inc.php
sudo gedit db.inc.php
如下修改:
$rcmail_config['db_dsnw'] = 'mysql://roundcubemail:pa5swd@localhost/roundcubemail';

配置主配置文件
sudo cp main.inc.php.dist main.inc.php
sudo gedit main.inc.php
如下修改:
$rcmail_config['default_host'] = 'localhost';
$rcmail_config['username_domain'] = 'pandy8.com';
$rcmail_config['mail_domain'] = 'mail.pandy8.com';
$rcmail_config['smtp_server'] = 'localhost';
$rcmail_config['product_name'] = 'RH Webmail';

重新启动httpd服务:
sudo service httpd restart;

进入:http://127.0.0.1/roundcubemail/
使用上面创建的:test@pandy8.com/test进入

查看收件箱,就能看到创建帐号自动发送的邮件,如果没有,那么到postfixadmin里面去尝试发送一个,就看见了。


Roundcube邮件系统的插件http://trac.roundcube.net/wiki/Plugin_Repository
配置managesieve插件, 提供过滤器,假期回复
sudo yum -y install dovecot-pigeonhole

配置dovecot配置文件
修改/etc/dovecot/dovecot.conf文件,做如下修改:
sudo gedit /etc/dovecot/dovecot.conf
protocols = pop3 imap sieve

修改/etc/dovecot/conf.d/15-lda.conf文件,做如下修改:
sudo gedit /etc/dovecot/conf.d/15-lda.conf
mail_plugins = quota sieve

重新启动dovecot
sudo service dovecot restart

Dovecot监听4190端口
netstat -tunlp | grep 4190
tcp        0      0 0.0.0.0:4190                0.0.0.0:*                   LISTEN      2188/dovecot

managesieve配置文件修改,将模板复制成config.inc.php,做如下修改:
[root@mail config]#cd /var/www/html/roundcubemail/plugins/managesieve/
[root@mail managesieve]# cp config.inc.php.dist config.inc.php
[root@mail managesieve]# gedit config.inc.php
修改以下内容:
$rcmail_config['managesieve_port'] = 4190;

使插件生效
修改/var/www/html/config/main.inc.php文件
sudo gedit /var/www/html/roundcubemail/config/main.inc.php
修改以下内容:
$rcmail_config['plugins'] = array('managesieve');

测试插件
Managesieve界面

更多插件的配置见
Roundcube Webmail 多域及插件配置篇:http://blog.dvxj.com/pandola/roundcube-webmail-plugins.html
$rcmail_config['plugins'] = array('managesieve','password','filesystem_attachments', 'emoticons', 'example_addressbook', 'message_highlight','jqueryui','globaladdressbook','userinfo','markasjunk','enigma','vcard_attachments','help');
加了6个插件,为啥是6个,因为那个jqueryui是其他插件要用的脚本,所以具体插件数目是6个,array圆括号内的参数,单引号引起来的,比如'password',引号内的内容,一定是和plugins目录中插件目录名一致,这样Roundcube才会根据配置,加载相应的插件。
globaladdressbook:全局地址簿,这个功能其实不错,可以让域管理员统一提前配置好公司所有人的邮件地址,这样大家发邮件的时候就可以使用现成的了。当然,这个不影响每个用户自己私人的地址簿,是分开的。
sudo cp -rf /home/pandy/下载/global-address-book /var/www/html/roundcubemail/plugins/
compose_addressbook:是写邮件时,可以通过点击一个按钮,弹出窗口调出地址簿,让你选择收件人,抄送、密送等邮件地址;
sudo cp -rf /home/pandy/下载/compose_addressbook /var/www/html/roundcubemail/plugins/
message_highlight: 高亮显示
sudo cp -rf /home/pandy/下载/message_highlight /var/www/html/roundcubemail/plugins/
注意,这些名字在下载后是有修改过的,有些没配置成功,那就像钓@鱼@岛问题一样,留给后人。


皮肤:
sudo gedit /var/www/html/roundcubemail/config/main.inc.php
$rcmail_config['skin'] = 'larry'; //默认皮肤
$rcmail_config['skin'] = 'classic';




Claws Mail客户端连接:
前提:
CentOS6.4邮件配置二: Bind安装配置 DNS服务器 http://panyongzheng.iteye.com/blog/1882011
CentOS6.4邮件配置三: 花生壳 + 自定义DNS解析 + Dovecot 配置收外网信件: http://panyongzheng.iteye.com/blog/1883439
#sudo yum -y install claws-mail
帐号设置:
帐号名称:test@pandy8.com
邮件地址:test@pandy8.com
通信协议POP3:
接受服务器:pandy8.com
SMTP服务器(发送):pandy8.com
用户ID:pandy8.com
密码:**********
就可以了,在Windows下面差不多一样设置.





修改端口:
sudo gedit /etc/dovecot/dovecot.conf
里面有说明:
# If you want to specify ports for each service, you will need to configure
# these settings inside the protocol imap/pop3 { ... } section, so you can
# specify different ports for IMAP/POP3. For example:
# protocol imap {
# listen = *:10143
# ssl_listen = *:10943
# ..
# }
# protocol pop3 {
# listen = *:10100
# ..
# }


问题:
1. dovecot测试 -ERR Authentication failed
http://hi.baidu.com/lijunyi0198/item/977522993c76838a591461eb

2. Connection closed by foreign host
确保运行dovecot服务,sudo chkconfig postfix on , service dovecot restart;
http://www.pooy.net/connection-closed-foreign-host.html
造成这个原 因是因为原来连接到SSHD服务器进程的22端口,当你的客户端突然断开时,服务器端的TCP连接就处于一个半打开状态。当下一次同一客户机再次建立 TCP连接时,服务器检测到这个半打开的TCP连接,并向客户机回传一个置位RST的TCP报文,客户机就会显示connection closed by foreign host。
这是TCP协议本身的一个保护措施,并不是什么错误,你只要再重新连接服务器就能连上。
我用的是wifi,然后登录路由之后,断网,自动的重新链接即可了!

3. Mailbox doesn't exist: INBOX
  vim /etc/dovecot/conf.d/10-mail.conf
  mail_location = maildir:%hMaildir, 否则会报这个错误

4.解决httpd: Could not reliably determine the server's fully qualified domain name, using 127.0.0.1 for ServerName
http://hi.baidu.com/luocs224/item/ec12e43f04c77f677c034b83
配置文件:/etc/httpd/conf/httpd.conf

5. 日志文件:sudo gedit /var/log/maillog

6. 收信不成功,看后台日志:
Error: user test@pandy8.com: Initialization failed: Initializing mail storage from mail_location setting failed: mkdir(/var/vmail/pandy8.com/test/Maildir) failed: Permission denied (euid=2000(vmail) egid=2000(vmail) missing +w perm: /var/vmail/pandy8.com, euid is not dir owner)

7. 收信不成功,看后台日志:
postfix/local[2670]: 74CD9281454: to=<test@pandy8.com>, relay=local, delay=0.33, delays=0.11/0.17/0/0.05, dsn=5.1.1, status=bounced (unknown user: "test")
http://stackoverflow.com/questions/18377813/postfix-status-bounced-unknown-user-myuser
mydestination = localhost  //使用这个
#mydestination = $myhostname, localhost.$mydomain, localhost, $mydomain //注释掉这个。


8. 客户端连接
http://www.extmail.net/forum/viewthread.php?tid=24693&page=1
#sudo gedit /etc/postfix/main.cf
改成:
inet_interfaces = all
mynetworks = 127.0.0.1,192.168.1.0/24
客户端===>让软件自动寻找也可以
pop.pandy8.com、pop3.pandy8.com
smtp.pandy8.com

9.Linux下面使用Claws Mail发送邮件“Relay access denied,客户端才有这个问题,roundcubemail是看不到这个问题的,因为roundcubemail是使用localhost来地址来发信。
修复Postfix 的Relay access denied问题 http://laravel.iteye.com/blog/1928259
注意,这个问题很奇怪,在Linux下的Virsualbox出错,但是到Windows去启动Virsualbox并发送邮件,也会同时把出错的邮件一起发送。
分享到:
评论
7 楼 pyzheng 2013-09-28  
yungdeguo 写道
pyzheng 写道
yungdeguo 写道
楼主,
能否有空研究一下roundcubemail的password插件么?

网上找了些方法能修改密码,但改了后就登陆不了。
如这个
$rcmail_config['password_query'] = "UPDATE mailbox SET password=ENCRYPT(%p,concat(_utf8'$1$',right(m(rand()),8),_utf8'$')) WHERE username=%u LIMIT 1";


我看了下mysql中存储的是sha256格式。
e02d374fde0dc75a17a557039a3a5338c7743304777dccd376f332bee68d2cf6
而插件修改后成了这样的格式
$1$6ca8e2a7$qUpkbGEqNFhiBPf416Xql/

希望你有空测试一下。

谢谢!

登录不了有许多原因,密码多空格了么? 能否其他地方的配置没有链接到数据库?或者php的加密解密没配置对?你可以尝试跟踪php源码看看?等等等.... 我的配置没问题,  我每一次都是复制粘贴复制粘贴就完事了,你看看是否其他地方没配置完?
我现在都不弄这个了,也没时间去看了 要忙自动截图的功能,你自己加油啦.....



非常感谢。

此问题已经解决了。
总结原因是自己不懂英语,不看文件说明。

把这段
$rcmail_config['password_query'] = 'SELECT update_passwd(%c, %u)';
改成
$rcmail_config['password_query'] = 'UPDATE mailbox SET password=%D WHERE username=%u';

此段也是网上找到的,照别人抄过来 password=%c,换成 password=%D就行了。

恭喜你   我也只是那时候换用Linux来工作  后来尝试用来做服务器  发现这个好玩  就试一下   现在不弄网络了  所以无法给你太多帮助  不好意思
6 楼 yungdeguo 2013-09-28  
pyzheng 写道
yungdeguo 写道
楼主,
能否有空研究一下roundcubemail的password插件么?

网上找了些方法能修改密码,但改了后就登陆不了。
如这个
$rcmail_config['password_query'] = "UPDATE mailbox SET password=ENCRYPT(%p,concat(_utf8'$1$',right(m(rand()),8),_utf8'$')) WHERE username=%u LIMIT 1";


我看了下mysql中存储的是sha256格式。
e02d374fde0dc75a17a557039a3a5338c7743304777dccd376f332bee68d2cf6
而插件修改后成了这样的格式
$1$6ca8e2a7$qUpkbGEqNFhiBPf416Xql/

希望你有空测试一下。

谢谢!

登录不了有许多原因,密码多空格了么? 能否其他地方的配置没有链接到数据库?或者php的加密解密没配置对?你可以尝试跟踪php源码看看?等等等.... 我的配置没问题,  我每一次都是复制粘贴复制粘贴就完事了,你看看是否其他地方没配置完?
我现在都不弄这个了,也没时间去看了 要忙自动截图的功能,你自己加油啦.....



非常感谢。

此问题已经解决了。
总结原因是自己不懂英语,不看文件说明。

把这段
$rcmail_config['password_query'] = 'SELECT update_passwd(%c, %u)';
改成
$rcmail_config['password_query'] = 'UPDATE mailbox SET password=%D WHERE username=%u';

此段也是网上找到的,照别人抄过来 password=%c,换成 password=%D就行了。
5 楼 pyzheng 2013-09-27  
yungdeguo 写道
楼主,
能否有空研究一下roundcubemail的password插件么?

网上找了些方法能修改密码,但改了后就登陆不了。
如这个
$rcmail_config['password_query'] = "UPDATE mailbox SET password=ENCRYPT(%p,concat(_utf8'$1$',right(m(rand()),8),_utf8'$')) WHERE username=%u LIMIT 1";


我看了下mysql中存储的是sha256格式。
e02d374fde0dc75a17a557039a3a5338c7743304777dccd376f332bee68d2cf6
而插件修改后成了这样的格式
$1$6ca8e2a7$qUpkbGEqNFhiBPf416Xql/

希望你有空测试一下。

谢谢!

登录不了有许多原因,密码多空格了么? 能否其他地方的配置没有链接到数据库?或者php的加密解密没配置对?你可以尝试跟踪php源码看看?等等等.... 我的配置没问题,  我每一次都是复制粘贴复制粘贴就完事了,你看看是否其他地方没配置完?
我现在都不弄这个了,也没时间去看了 要忙自动截图的功能,你自己加油啦.....
4 楼 yungdeguo 2013-09-27  
楼主,
能否有空研究一下roundcubemail的password插件么?

网上找了些方法能修改密码,但改了后就登陆不了。
如这个
$rcmail_config['password_query'] = "UPDATE mailbox SET password=ENCRYPT(%p,concat(_utf8'$1$',right(m(rand()),8),_utf8'$')) WHERE username=%u LIMIT 1";


我看了下mysql中存储的是sha256格式。
e02d374fde0dc75a17a557039a3a5338c7743304777dccd376f332bee68d2cf6
而插件修改后成了这样的格式
$1$6ca8e2a7$qUpkbGEqNFhiBPf416Xql/

希望你有空测试一下。

谢谢!
3 楼 pyzheng 2013-09-12  
噢  配置邮件是前端事件尝试而已   现在都不弄了  哈哈  加油.....
2 楼 yungdeguo 2013-09-12  
yungdeguo 写道
postfixadmin最后建管理员帐号时提示


Everything seems fine... attempting to create/update database structure

Database is up to date
can't encrypt password with dovecotpw, see error log for details

应该如何排查啊?
谢谢!



谢谢!
已经解决了。

原因是因为postfixadmin中config.inc.php
// If you use the dovecot encryption method: where is the dovecotpw binary located?
$CONF['dovecotpw'] = "/usr/sbin/dovecotpw";

已经变成了
$CONF['dovecotpw'] = "/usr/bin/doveadm pw";

这步完了,新问题又来了。再努力解决!
1 楼 yungdeguo 2013-09-11  
postfixadmin最后建管理员帐号时提示


Everything seems fine... attempting to create/update database structure

Database is up to date
can't encrypt password with dovecotpw, see error log for details

应该如何排查啊?
谢谢!

相关推荐

Global site tag (gtag.js) - Google Analytics