postfix+mysql+mailman

目标:
使用postfix做SMTP发送邮件,并且可以支持邮件列表功能。并且可以方便的添加邮件列表
方案:
使用postfix做SMTP,mailman做邮件列表,postfixadmin管理postfix账号,邮件列表功能需要存储在MySQL中,方便程序控制
步骤一,安装apache和php支持
yum install httpd php php-mysql
步骤二,安装MySQL和postfix,并使postfix支持MySQL

yum install mysql mysql-server mysql-devel

yum install postfix
首先需要确认postfix支持mysql,默认安装的postfix不支持mysql
1)查看postfix是否支持mysql,使用命令”postconf -m”,没有mysql,说明目前不支持mysql。
2)使postfix支持mysql
3)MySQL的权限(如需要)
设置密码
mysqladmin -uroot password ‘newpassword’
允许任意位置访问
GRANT ALL ON *.* TO root@”%” IDENTIFIED BY ‘newpassword’ WITH GRANT OPTION;
4)postfix配置,按照http://www.zftown.com/centos/make/postfix_smtp.html
步骤三,安装postfixadmin,管理Postfix
1)建立postfix使用的数据库
mysql>create database postfix;
mysql>grant all privileges on postfix.* to postfix#localhost identified by ‘123456’;  (将#换为@)
mysql>flush privileges;
2)下载解压postfix,并移到web目录下使其可以被访问
步骤四,将postfix与postfixadmin绑定
修改配置文件:

vi config.inc.php

找到下面的参数并作修改:

$CONF[‘configured’] = true;
$CONF[‘database_password’] = ‘postfix_password’;
$CONF[‘default_language’] = ‘cn’;
$CONF[‘used_quotas’] = ‘YES’;
$CONF[‘quota’] = ‘YES’;

postfix_password即上一步设置的postfix用户密码。
打开浏览器,输入下面的网址开始安装:

http://your-domain/postfixadmin/setup.php
postfix与postfixadmin整合

vi /etc/postfix/main.cf

按如下添加或修改:

virtual_mailbox_domains = proxy:mysql:/etc/postfix/sql/mysql_virtual_domains_maps.cf
virtual_alias_maps =
proxy:mysql:/etc/postfix/sql/mysql_virtual_alias_maps.cf,
proxy:mysql:/etc/postfix/sql/mysql_virtual_alias_domain_maps.cf,
proxy:mysql:/etc/postfix/sql/mysql_virtual_alias_domain_catchall_maps.cf
virtual_mailbox_maps =
proxy:mysql:/etc/postfix/sql/mysql_virtual_mailbox_maps.cf,
proxy:mysql:/etc/postfix/sql/mysql_virtual_alias_domain_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, the user’s maildir has overdrawn his diskspace quota, please try again later.
virtual_overquota_bounce = yes

建立目录sql

mkdir /etc/postfix/sql

以下的几个文件注意修改postfix_password。

vi /etc/postfix/sql/mysql_virtual_alias_maps.cf

内容:

user = postfix
password = postfix_password
hosts = localhost
dbname = postfix
query = SELECT goto FROM alias WHERE address=’%s’ AND active = ‘1’
#expansion_limit = 100

vi /etc/postfix/sql/mysql_virtual_alias_domain_maps.cf

内容:

user = postfix
password = postfix_password
hosts = localhost
dbname = postfix
query = SELECT goto FROM alias,alias_domain WHERE alias_domain.alias_domain = ‘%d’ and alias.address = CONCAT(‘%u’, ‘@’, alias_domain.target_domain) AND alias.active = 1 AND alias_domain.active=’1′

vi /etc/postfix/sql/mysql_virtual_alias_domain_catchall_maps.cf

内容:

# handles catch-all settings of target-domain
user = postfix
password = postfix_password
hosts = localhost
dbname = postfix
query  = SELECT goto FROM alias,alias_domain WHERE alias_domain.alias_domain = ‘%d’ and alias.address = CONCAT(‘@’, alias_domain.target_domain) AND alias.active = 1 AND alias_domain.active=’1′

vi /etc/postfix/sql/mysql_virtual_domains_maps.cf

内容:

user = postfix
password = postfix_password
hosts = localhost
dbname = postfix
query          = SELECT domain FROM domain WHERE domain=’%s’ AND active = ‘1’
#query          = SELECT domain FROM domain WHERE domain=’%s’
#optional query to use when relaying for backup MX
#query           = SELECT domain FROM domain WHERE domain=’%s’ AND backupmx = ‘0’ AND active = ‘1’
#expansion_limit = 100

vi /etc/postfix/sql/mysql_virtual_mailbox_maps.cf

内容:

user = postfix
password = postfix_password
hosts = localhost
dbname = postfix
query  = SELECT maildir FROM mailbox WHERE username=’%s’ AND active = ‘1’
#expansion_limit = 100

vi /etc/postfix/sql/mysql_virtual_alias_domain_mailbox_maps.cf

内容:

user = postfix
password = postfix_password
hosts = localhost
dbname = postfix
query = SELECT maildir FROM mailbox,alias_domain WHERE alias_domain.alias_domain = ‘%d’ and mailbox.username = CONCAT(‘%u’, ‘@’, alias_domain.target_domain) AND mailbox.active = 1 AND alias_domain.active=’1′

vi /etc/postfix/sql/mysql_virtual_mailbox_limit_maps.cf

内容:

user = postfix
password = postfix_password
hosts = localhost
dbname = postfix
query = SELECT quota FROM mailbox WHERE username=’%s’ AND active = ‘1’

赞(0)
未经允许不得转载:代码'S Blog » postfix+mysql+mailman
分享到: 更多 (0)