首页 > 代码库 > 架设邮件服务器之postfix&Dovecot

架设邮件服务器之postfix&Dovecot

本教程来自http://blog.pztop.com/2016/04/20/Email-Server-With-Postfix-Dovecot-MailScanner-2/

本教程仅仅做翻译和注释,版权归原作者所有。

----------------------------------正文-----------------------------

postfix负责发信,dovecot负责收信(imap和pop3),一起完美构成邮件服务器。

我们使用MariaDB作为postfix用户和域名的数据依赖。现在连接并创建新数据库。

mysql -uroot -p
CREATE DATABASE postfix;
CREATE USER postfix@localhost IDENTIFIED BY PApassword;
GRANT ALL PRIVILEGES ON postfix.* TO postfix@localhost;
FLUSH PRIVILEGES;
QUIT;

安装postfix admin后台管理页面

cd /usr/local/src
wget http://downloads.sourceforge.net/project/postfixadmin/postfixadmin/postfixadmin-2.93/postfixadmin-2.93.tar.gz
tar zvxf postfixadmin-2.93.tar.gz
rm -rf /var/www/html/postfixadmin 
mv postfixadmin-2.93 /var/www/html/postfixadmin
chown -R nginx:nginx /var/www/html/postfixadmin

编辑配置文件

vim /var/www/html/postfixadmin/config.inc.php

按下面修改

<?php
$CONF[configured] = true;

$CONF[database_type] = mysqli;
$CONF[database_user] = postfix;
$CONF[database_password] = PApassword;
$CONF[database_name] = postfix;
?>

创建session文件夹并赋予权限

mkdir /var/lib/php/session/
chown -R nginx:nginx /var/lib/php/session/

postfix admin后台设置

现在可以打开https://postfixadmin.mydomain.com/setup.php,点击忘记setup password的忘记密码,输入自己想要的密码,会得到一段hash值,复制到/var/www/html/postfixadmin/config.inc.php第30行

$CONF[setup_password] = 82020bc067e2a6deaa3fba3632529114:0834f649bf09ee930910ab1b353e3f0722b77ee8;

这样就可以登录,登录后可以创建域名和用户

https://postfixadmin.mydomain.com/users/login.php这是普通用户的登录地址。

BUG修复

在后台点击Fetch email会出现错误,打开/var/www/html/postfixadmin/model/PFAHandler.php572行,修改

$base64_decode = "###KEY###";

连接postfix到MariaDB

创建5个配置文件,复制代码

vim /etc/postfix/mysql-virtual_domains_maps.cf
hosts = localhost
user = postfix
password = PApassword
dbname = postfix
query = SELECT domain FROM domain WHERE domain=%s AND backupmx = 0 AND active = 1
vim /etc/postfix/mysql-relay_domains_maps.cf
hosts = localhost
user = postfix
password = PApassword
dbname = postfix
query = SELECT domain FROM domain WHERE domain=%s and backupmx = 1
vim /etc/postfix/mysql-virtual_mailbox_maps.cf
hosts = localhost
user = postfix
password = PApassword
dbname = postfix
query = SELECT maildir FROM mailbox WHERE username=%s AND active = 1
vim /etc/postfix/mysql-virtual_mailbox_limit_maps.cf

 

架设邮件服务器之postfix&Dovecot