postfix-2.11.3.tar.gz
postfix常用命令查看:
postconf -m
可以列出可用的插件
make tidy
清理之前安装的文件(再次安装之前执行)
postconf -a
支持的认证方式
postconf mail_version
查看postfix的版本号(不能通过rpm -q查看)
make install
交互式安装(第一次安装时用)
make upgrade
非交互式安装(postfix更新)
mkae -f Makefile.init makefile (默认方式生成makefile)
首先进行基础软件的安装
2.准备安装的软件:
注释:我们默认实验机器只安装了基本的软件,所以要安装以下软件。
yum install -y db*-devel gcc
yum install mysql-devel -y (mysql编译的头文件和库)
yum install httpd
一.生成带有mysql插件的makefile
这条命令中要设置mysql的编译的头文件目录和mysql所使用库的目录,这些文件的目录以本机的实际情况为准:
查看mysql的头文件和库的位置:
rpm -ql mysql-devel(库文件以.so结尾)
1.cd postfix-2.11.3
2.把头文件和库文件的目录添加到make命令中:
使用yum源安装的mysql
make -f Makefile.init makefiles 'CCARGS=-DHAS_MYSQL -I/usr/include/mysql' 'AUXLIBS=-L/usr/lib64/mysql -lmysqlclient -lz -lm'
自己源码编译的mysql
make -f Makefile.init makefiles 'CCARGS=-DHAS_MYSQL -I/usr/local/lnmp/mysql/include/' 'AUXLIBS=-L/usr/local/lnmp/mysql/lib -lmysqlclient -lz -lm'
报错:
bin/postconf: error while loading shared libraries: libmysqlclient.so.18: cannot open shared object file: No such file or directory
解决:先去自己的mysql的lib目录下看一下是否有libmysqlclient.so.18,如果有的话做一个软链接
ln -s /usr/local/lnmp/mysql/lib/libmysqlclient.so.18 /usr/lib64/
3.生成完成makefies文件之后,然后重新进行更新:
make upgrade
4修改/etc/postfix/main.cf文件:
inet_interfaces=all
也可以通过如下方法修改
postconf -n
postconf -e inet_interfaces=all
5重新启动postfix服务:
/etc/init.d/postfix restart
6.安装邮件发送软件:
yum install -y mailx
二.配置mysql和postfix:
1.安装extmail软件的网络前端和后端:
extmail-1.2.tar.gz
(网络前端)
extman-1.1.tar.gz
(网络后端)
2.创建extmail的默认发布目录:
mkdir /var/www/extsuite
tar xvf extmail-1.2.tar.gz -C /var/www/extsuite
tar xvf extman-1.1.tar.gz -C /var/www/extsuite
3把目录名修改便于访问:
cd /var/www/extsuite
mv extmail-1.2 extmail
mv extman-1.1 extman
为什么我们要创建默认发布目录为/var/www/extsuite,由配置文件决定:
vim /var/www/extmail/webmail.cf.default
4.把extman的sql语句导入到mysql数据库中:
cd /var/www/extsuite/extman/docs
导入extmail自带数据库:
mysql -uroot -pcentrald < extmail.sql
报错:
# mysql -pcentrald <extmail.sql
ERROR 1064 (42000) at line 50: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'TYPE=MyISAM COMMENT='Ext/Webman - Admin Accounts'' at line 15
原因:编写数据库的版本比当前安装的版本低。
解决:
(1)、用文本编辑器打开extmail.sql;
(2)、查找/替换,将数据库文件内的所有TYPE=MyISAM修改为ENGINE=MyISAM,保存退出;
vim extmail.sql
%s/TYPE=MyISAM/ENGINE=MyISAM/g
5.vim init.sql
(修改[email protected]的密码为westos)
(修改[email protected]的密码为westos)
因为原始的加密密码太长,而且我们不知道,我们修改它的密码为centrald,并且在配置文件设置为明文访问
6.导入extmail的测试帐号:
mysql -uroot -pcentrald < init.sql
7.添加完成后用extmail进入mysql查看表是否存在:
mysql -uextmail -pextmail
8.
# cp mysql_virtual_alias_maps.cf mysql_virtual_domains_maps.cf mysql_virtual_mailbox_maps.cf /etc/postfix/
9.
# cd /etc/postfix/
10添加用户
# useradd -u 800 -s /sbin/nologin vmail
11
postconf -e inet_interfaces=all
postconf -e virtual_mailbox_base=/home/vmail
postconf -e virtual_uid_maps=static:800
postconf -e virtual_gid_maps=static:800
postconf -e virtual_mailbox_maps=mysql:/etc/postfix/mysql_virtual_mailbox_maps.cf
postconf -e virtual_mailbox_domains=mysql:/etc/postfix/mysql_virtual_domains_maps.cf
postconf -e virtual_alias_maps=mysql:/etc/postfix/mysql_virtual_alias_maps.cf
查看是否添加成功
postconf -n
12.重新读取配置文件
postfix reload
13测试:
yum install mailx
mail [email protected]
mailq(查看邮件队列)
tail -f /var/log/maillog
14 在/home/vmail下查看vmail里的内容
如果在vmail里生成文件,说明邮件发送成功
注意:
(1)[root@dektop115 docs]# postsuper -d ALL
删除邮件队列
(2)Postfix使用过程中出现如下报错,我们将网络协议指定为IP4即可.
/usr/sbin/postconf: warning: inet_protocols: disabling IPv6 name/address support: Address family not supported by protocol
查看当前inet_protocols
# /usr/sbin/postconf |grep inet_protocols
inet_protocols = all
修改ipv4
# vim /etc/postfix/main.cf
inet_protocols = all
改为
inet_protocols = ipv4
三.配置WEB收信服务
1.修改配置文件
cd /var/www/extsuite/extmail
cp webmail.cf.default webmail.cf (%60 140行)
(拷贝配置文件模板)
vim webmail.cf
SYS_MAILDIR_BASE = /home/vmail
SYS_CRYPT_TYPE = plain
SYS_MYSQL_USER = extmail
SYS_MYSQL_PASS = extmail
2.修改apache配置文件并登录extmail
拷贝内容到httpd.conf:
(1)vim /var/www/extsuite/extmail/INSTALL
要拷贝内容:
NameVirtualHost *:80
<VirtualHost *:80>
ServerName mail.example.com
DocumentRoot /var/www/extsuite/extmail/html/
ScriptAlias /extmail/cgi /var/www/extsuite/extmail/cgi
Alias /extmail /var/www/extsuite/extmail/html
SuexecUserGroup vuser vgroup
</VirtualHost>
(2)vim /etc/httpd/conf/httpd.conf
NameVirtualHost *:80
<VirtualHost *:80>
ServerName mail.extmail.org
DocumentRoot /var/www/extsuite/extmail/html/
ScriptAlias /extmail/cgi /var/www/extsuite/extmail/cgi
Alias /extmail /var/www/extsuite/extmail/html
SuexecUserGroup vmail vmail
</VirtualHost>
注:在实际的配置中,一直是suexe的问题,所以将suexe注释掉
NameVirtualHost *:80
User vmail
Group vmail
<VirtualHost *:80>
ServerName mail.extmail.org
DocumentRoot /var/www/extsuite/extmail/html/
ScriptAlias /extmail/cgi /var/www/extsuite/extmail/cgi
Alias /extmail /var/www/extsuite/extmail/html
</VirtualHost>
重启httpd服务器
[root@desktop119 extmail]# /etc/init.d/httpd restart
要在客户机上做一个映射,/etc/hosts.
192.168.3.44 mail.extmail.org
(3)
这个时候访问不了,缺少CGI语言支持
sc3
安装它:
yum install perl-CGI -y
(4)依旧报错:
Unix::Syslog not found,
sc4
此时我们应该先把日志功能关闭掉.
vim /var/www/extsuite/extmail/webmail.cf
SYS_LOG_ON = 0
(关闭日志功能)
(5)登录:
username: postmaster
password: westos
测试收信发信功能。
3.extmail后台管理界面:
1):
cd /var/www/extsuite/extman
cp webman.cf.default webman.cf
vim webman.cf
SYS_CRYPT_TYPE = plain
SYS_CAPTCHA_ON = 0
(关闭验证)
SYS_MAILDIR_BASE = /home/vmail
SYS_SESS_DIR = /tmp/
vim INSTALL
将以下内容拷贝到apache配置文件中:
ScriptAlias /extman/cgi /var/www/extsuite/extman/cgi
Alias /extman /var/www/extsuite/extman/html
vim /etc/httpd/conf/httpd.conf:
NameVirtualHost *:80
<VirtualHost *:80>
ServerName mail.extmail.org
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
常见问题解决
1.解决接收qq邮件乱码问题
收取qq发送来的邮件正文显示为乱码,而手动在编码选择GB2312没问题。截取部分邮件原始文件时发现qq的编码为gb18030,extmail会自动判别编码格式,并以该编码方式来显示。
但我的Perl(版本为5.10.1)缺少GB18030码表。因此通过增加Encode::HanExtra码表模块的支持,可以解决此问题。
# wget -c http://search.cpan.org/CPAN/authors/id/A/AU/AUDREYT/Encode-HanExtra-0.23.tar.gz # tar -zxf Encode-HanExtra-0.23.tar.gz # cd Encode-HanExtra-0.23 # perl Makefile.PL # perl Makefile # make install
2.解决回复邮件出现html格式的问题
extmail回复转发邮件时候,邮件都会出现html源代码。使用chrome时候,每次回复转发都会出现html源代码
(1)登陆邮箱,选择个人偏好设置–>常规设置–>写邮件设置–> RTF邮件–>取消勾选“是否打开RTF(富文本格式)编辑器?勾选将在编写邮件时打开”
(2)其实,extmail用户的这个是否打开RTF功能,是以文件的形式/保存在用户邮箱目录的,/home/vmail/itaoxue.me/centrald/Maildir/user.cf
登陆用户目录去一个个改也比较慢,因此写了个shell。它会遍历/home/vmail/itaoxue.me/这个目录,
如果用户已经有配置过“个人偏好设置”,那用户邮箱里就有user.cf,shell脚本就只修改compose_html 这个参数,确保不会覆盖用户其它设置
如果用户没有配置过“个人偏好设置”,那用户邮箱里里就不会有user.cfshell脚本就在用户邮箱目录里创建user.cf
#!/bin/bash filepath="/home/vmail/itaoxue.me" for user in `ls ${filepath}` do if [ -f ${filepath}/$user/Maildir/user.cf ] then echo "existing!!!" sed -i 's/compose_html = 1/compose_html = 0/' ${filepath}/$user/Maildir/user.cf else echo "None" cat >${filepath}/$user/Maildir/user.cf<<\eof ccsent = 1 pop_on = 0 nick_name = compose_html = 0 pop_files = 30 conv_link = 1 delmode = on pop_timeout = 30 template = default timezone = +0800 lang = zh_CN charset = UTF-8 trylocal = 1 addr2abook = 1 page_size = 100 sort = Dt show_html = 1 screen = auto full_header = 0 eof chown vmail.vmail ${filepath}/$user/Maildir/user.cf fi done
四.配置MUA(pop3的添加)
1.安装dovecot软件
yum install -y dovecot dovecot-mysql
2.dovecot配置文件
(1)vim /etc/dovecot/dovecot.conf
protocols = imap pop3 lmtp
(2)vim /etc/dovecot/conf.d/10-mail.conf
mail_location = maildir:/home/vmail/%d/%n/Maildir
first_valid_uid = 800
(3)vim /etc/dovecot/conf.d/10-auth.conf
#!include auth-system.conf.ext
!include auth-sql.conf.ext
#!include auth-ldap.conf.ext
#!include auth-passwdfile.conf.ext
#!include auth-checkpassword.conf.ext
#!include auth-vpopmail.conf.ext
(4)vim /etc/dovecot/conf.d/auth-sql.conf.ext
args = /etc/dovecot/dovecot-sql.conf.ext
(5)拷贝模板文件
cp /usr/share/doc/dovecot-2.0.9/example-config/dovecot-sql.conf.ext /etc/dovecot/
(6)vim /etc/dovecot/dovecot-sql.conf.ext
driver = mysql
connect = host=/var/lib/mysql/mysql.sock dbname=extmail user=extmail password=extmail
default_pass_scheme = PLAIN
password_query = \
SELECT username, domain, password \
FROM mailbox WHERE username = '%u' AND domain = '%d'
user_query = \
SELECT maildir,800 AS uid,800 AS gid \
FROM mailbox WHERE username = '%u'
3.启动dovecot
/etc/init.d/dovecot start
4.使用telnet测试dovecot
telnet 112.74.81.237 110
Trying 112.74.81.237...
Connected to 112.74.81.237.
Escape character is '^]'.
+OK Dovecot ready.
问题解决:
启动dovecot报错
# /etc/init.d/dovecot start
Starting Dovecot Imap: Error: socket() failed: Address family not supported by protocol
Error: service(pop3-login): listen(::, 110) failed: Address family not supported by protocol
Error: socket() failed: Address family not supported by protocol
Error: service(pop3-login): listen(::, 995) failed: Address family not supported by protocol
Error: socket() failed: Address family not supported by protocol
Error: service(imap-login): listen(::, 143) failed: Address family not supported by protocol
Error: socket() failed: Address family not supported by protocol
Error: service(imap-login): listen(::, 993) failed: Address family not supported by protocol
Fatal: Failed to start listeners
[FAILED]
有可能是IPV6的支持被关掉了,改下配置文件,把监听IPV6地址的选项去掉即可
# vi /etc/dovecot/dovecot.conf
默认是
#listen = *, ::
改为
listen = *
# /etc/init.d/dovecot start
Starting Dovecot Imap: [ OK ]
五.Postfix sals认证配置和tls加密配置
(1)删除旧的加密文件
cd /etc/pki/dovecot/certs/
rm -fr *
cd /etc/pki/dovecot/private/
rm -fr *
(2)生成新的加密文件
cd /etc/pki/tls/certs/
make dovecot.pem
(3)将生成的加密文件拷贝到指定目录
cp dovecot.pem ../../dovecot/certs/
cp dovecot.pem ../../dovecot/private/
(4)重启dovecot
/etc/init.d/dovecot restart