首页 | 邮件资讯 | 技术教程 | 解决方案 | 产品评测 | 邮件人才 | 邮件博客 | 邮件系统论坛 | 软件下载 | 邮件周刊 | 热点专题 | 工具
网络技术 | 操作系统 | 邮件系统 | 客户端 | 电子邮箱 | 反垃圾邮件 | 邮件安全 | 邮件营销 | 移动电邮 | 邮件软件下载 | 电子书下载

邮件服务器

技术前沿 | Qmail | IMail | MDaemon | Exchange | Domino | 其它 | Foxmail | James | Kerio | JavaMail | WinMail | Sendmail | Postfix | Winwebmail | Merak | CMailServer | 邮件与开发 | 金笛 |
首页 > 邮件服务器 > Postfix > 基於FreeBSD6.1功能完善的mail system > 正文

基於FreeBSD6.1功能完善的mail system

出处:www.freebsdchina.org/forum 作者:@kang 时间:2006-10-25 18:21:00
Email System Install Manual
ver1.1

說明 :
測試域名:test.com ; hostname=mail.test.com
系統環境 :

Postfix + PostfixAdmin + MySQL + Apache22 + PHP4 + PHP4-Session + Cyrus-sasl + Courier-imap + Maildrop + Squirrelmail +ClamAV+Amavisd-new+SpamAssassin

1 OS:FreeBSD 6.1 Release
2 mysql-server-5.x:/usr/ports/database/mysql50-server
3 apache-2.2.x:/usr/ports/www/apache22
4 php5-x:/usr/ports/lang/php5
5 php5-session-5.x:/usr/ports/www/php5-session
6 cyrus-sasl-2.x:/usr/ports/security/cyrus-sasl2
7 postfix-2.3.x:/usr/ports/mail/postfix
8 PostfixAdmin :/usr/ports/mail/postfixadmin
9 courier-imap-4.x:/usr/ports/mail/courier-imap
10 maildrop-1.x:/usr/ports/mail/maildrop
11 squirrelmail-1.4.x:/usr/ports/mail/squirrelmail
12 ClamAV(ClamAntiVirus):/usr/ports/security/clamav
13 Amavisd-new:/usr/ports/security/amavisd-new
14 SpamAssassin:/usr/ports/mail/p5-Mail-SpamAssassin

安裝前先更新port tree
系統采用最小化安裝
#cd /usr/ports/net/csup //切換到安裝路徑
#make install clean //安裝並清除過程中不必要的檔案
#cd /usr/share/examples/cvsup //路徑
#cp ports-supfile /root/ //放到/usr下(看你高興要放哪)
#cd /root
#vi ports-supfile //修改原更新站台位置內容如下
default host CHANGE_THIS.FreeBSD.org //官方站台(預設值)
default host cvsup.cn.freebsd.org //改為國內站台,如此下載速度較快
#cd /root //切換路徑
#rehash //才不會出現指令無效訊息(csup: Command not found.)
#csup -L 2 ports-supfile //開始更新
#cd /usr/ports;make fetchindex //或取ports INDEX文件,可以不做這步

安裝 MySQL50 ( Server/Client )
官方網站:http://www.mysql.com
#cd /usr/ports/databases/mysql50-server/
#make install clean

#vi /etc/rc.conf # 設定 mysql 開機自動啟動

mysql_enable="YES"

#/usr/local/etc/rc.d/mysql-server start # 手動啟動 mysql 。

#netstats -na |grep LISTEN # 確認 mysql server 有啟動

tcp4 0 0 *.3306 *.* LISTEN

Setp 2.

安裝 Apache2.2.x
官方網站 http://www.apache.org
#cd /usr/ports/www/apache22
#make install clean

#vi /etc/rc.conf # 設定 apache22 開機自動 up

apache22_enable="YES"
#vi /boot/loader.conf #添加 apache22的accf 選項
accf_http_local=”yes”

#vi /usr/local/etc/apache22/httpd.conf

ServerAdmin test@test.com
ServerName 127.0.0.1
AddDefaultCharset big5

#/usr/local/sbin/apachectl start
#ps -ax |grep http # 確認 apache 有啟動

70558 ?? Ss 0:00.06 /usr/local/sbin/httpd -k start
70559 ?? S 0:00.01 /usr/local/sbin/httpd -k start
70560 ?? S 0:00.01 /usr/local/sbin/httpd -k start
70561 ?? S 0:00.01 /usr/local/sbin/httpd -k start

Setp 3.

安裝 PHP5 + php5-session + cyrus-sasl2
官方網站 http://www.php.net
#cd /usr/ports/lang/php5
#make install clean
Options for php5.x # 選 apache,debug不選避免zend出錯
[X] APACHE Build Apache Module

#vi /usr/local/etc/apache22/httpd.conf # 修改 apache22 設定讓 php 運行在apache22

AddType application/x-httpd-php .php
AddType application/x-httpd-php-source .phps
DirectoryIndex index.php index.html index.html.var

#cd /usr/local/etc/
#cp php.ini-dist php.ini
#vi php.ini

register_globals =On # 修改 register_globals =Off 變成 On ,squirrelmail 會用得到

#cd /usr/ports/www/php5-session/ # 安裝 php5-session 是 postfixadmin 需要用到的,所以是必須要加裝的
官方網站 http://www.php.net
#make install clean

#apachectl restart # 重新起動 apache
#vi /usr/local/www/apache22/data/index.php
<?
phpinfo();
?>

測試 php5 有無安裝成功: http://192.168.2.130/index.php

# cd /usr/ports/security/cyrus-sasl2 # 安裝 cyrus-sasl
官方網站 http://cyrusimap.web.cmu.edu
# make install WITH_AUTHDAEMON=yes clean
#vi /usr/local/lib/sasl2/smtpd.conf # 配置 sasl SMTP 認證
方案一
pwcheck_method: authdaemond
log_level: 3
mech_list: PLAIN LOGIN
authdaemond_path:/var/run/authdaemond/socket

方案二,
pwcheck_method: auxprop
auxprop_plugin: sasldb
mech_list: plain login cram-md5 digest-md5

# saslpasswd2 –c smtpauth@ # 創建用戶smtpauth@,如果不加”@”,將創建形如username@hostname.
Password: # password : 123456
Again (for verification):
# sasldblistusers2 # 查看sasldb2.db
smtpauth@: userPassword
Setp 4.

安裝 Postfix
官方網站 http://www.postfix.org
#cd /usr/ports/mail/postfix
#make install WITH_AUTHDAEMON=yes clean
Postfix configuration options # 只選 SASL2 跟 MySQL
[X] SASL2 Cyrus SASLv2 (Simple Authentication and Security Layer)
[X] MySQL MySQL map lookups (choose version with WITH_MYSQL_VER)

Would you like to activate Postfix in /etc/mail/mailer.conf [n]? y # 選 yes

#vi /etc/rc.conf # 開機自動啟動 postfix
加入:
postfix_enable=”YES”
#echo ‘postfix: root’ >> /etc/aliases
#/usr/local/bin/newaliases
#chown postfix:postfix /etc/opiekeys

#vi /usr/local/etc/postfix/main.cf

myhostname = mail.test.com
mydomain = test.com
myorigin = $mydomain
mydestination = $myhostname localhost localhost.$mydomain
mynetworks = 192.168.2.0/24, 127.0.0.0/8
inet_interfaces = all
relay_domains = $mydestination

virtual_mailbox_base = /var/mailbox/
virtual_mailbox_maps = mysql:/usr/local/etc/postfix/mysql_virtual_mailbox_maps.cf
virtual_mailbox_domains = mysql:/usr/local/etc/postfix/mysql_virtual_domains_maps.cf
virtual_alias_domains =
virtual_alias_maps = mysql:/usr/local/etc/postfix/mysql_virtual_alias_maps.cf

virtual_uid_maps = static:5001
virtual_gid_maps = static:5001

virtual_transport = virtual
transport_maps = mysql:/usr/local/etc/postfix/mysql_virtual_transport_maps.cf

message_size_limit = 15728640
virtual_mailbox_limit = 2097152000
virtual_create_maildirsize = yes
virtual_mailbox_extended = yes

virtual_mailbox_limit_maps = mysql:/usr/local/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

broken_sasl_auth_clients = yes
smtpd_recipient_restrictions = permit_mynetworks
permit_sasl_authenticated
permit_auth_destination
reject_invalid_hostname
reject_unknown_sender_domain
reject_non_fqdn_sender
reject_non_fqdn_recipient
reject_unknown_recipient_domain
reject_unauth_pipelining
reject_unauth_destination
reject
smtpd_sasl_auth_enable = yes
smtpd_sasl_local_domain = $mydomain
smtpd_sasl_security_options = noanonymous
smtpd_sasl_application_name = smtpd
smtpd_client_restrictions = permit_sasl_authenticated
reject_non_fqdn_sender
reject_unknown_sender_domain
reject_sender_login_mismatch
smtpd_banner = $myhostname ESMTP "SZ Mail Server"

content_filter = smtp-amavis:[127.0.0.1]:10024


說明:同域多服務器情況
test.com 域下有A(廣州office) 、B(深圳office)兩台mail server ,A保存所有廣州office的郵箱;B 保存所有深圳office的郵箱。
廣州office:所有發往 “廣州office”內部的郵件將由A mail server進行本地投遞,發往 “深圳office” 的郵件將通過transport_maps (mail address list) 指向 B mail server 進行投遞。
深圳office:所有發往 “深圳office”內部的郵件將由B mail server進行本地投遞,發往 “廣州office”的郵件將通過transport_maps (mail address list) 指向 A mail server 進行投遞。
其中:A mail server 的transport_maps 記錄 “深圳office”的所有郵件地址;B mail server的transport_maps 記錄 “廣州office” 的所有郵件地址。

#mkdir /var/mailbox # 建立郵件存放目錄

#pw groupadd vmail -g 5001 # 建立 vmail 這個使用者帳號及群組
#pw useradd vmail -u 5001 -g 5001 -s/sbin/nologin -d/dev/null # 無home目錄及不可登錄系統。

#chown -R vmail:vmail /var/mailbox
#chmod -R ug+rwx,o-rwx /var/mailbox #(chmod –R 770 /var/mailbox)

#vi /usr/local/etc/postfix/mysql_virtual_alias_maps.cf # 建立MySQL 跟 postfix 之間的資料對應關聯文件,總共五個。
user = postfix
password = postfix
hosts = localhost
dbname = postfix
table = alias
select_field = goto
where_field = address

#vi /usr/local/etc/postfix/mysql_virtual_domains_maps.cf
user = postfix
password = postfix
hosts = localhost
dbname = postfix
table = domain
select_field = description
where_field = domain

#vi /usr/local/etc/postfix/mysql_virtual_transport_maps.cf
user = postfix
password = postfix
hosts = localhost
dbname = postfix
table = alias
select_field = transport_maps
where_field = mlist
#vi /usr/local/etc/postfix/mysql_virtual_mailbox_maps.cf
user = postfix
password = postfix
hosts = localhost
dbname = postfix
table = mailbox
select_field = maildir
where_field = username

#vi /usr/local/etc/postfix/mysql_virtual_mailbox_limit_maps.cf
user = postfix
password = postfix
hosts = localhost
dbname = postfix
table = mailbox
select_field = quota
where_field = username

#/usr/local/sbin/postfix start # 啟動 postfix


Setp 4.

安裝 Postfixadmin
官方網站 http://high5.net/postfixadmin
#cd /usr/ports/mail/postfixadmin/
#make install clean

#chown -R vmail:vmail /usr/local/www/postfixadmin # 修改所有 postfixadmin 的目錄資料夾權限
#cd /usr/local/www/postfixadmin
#chmod 640 *.php *.css
#cd /usr/local/www/postfixadmin/admin/
#chmod 640 *.php .ht*
#cd /usr/local/www/postfixadmin/images/
#chmod 640 *.gif *.png
#cd /usr/local/www/postfixadmin/languages/
#chmod 640 *.lang
#cd /usr/local/www/postfixadmin/templates/
#chmod 640 *.tpl
#cd /usr/local/www/postfixadmin/users/
#chmod 640 *.php

#cd /usr/local/www/postfixadmin # 建立 Postfixadmin 的 MySQL 資料庫
vi DATABASE_MYSQL.TXT # 在以下位置新增兩行,加下劃線紅色的為新增行
# Table structure for table alias # ailas表中存儲alias 和transport_maps 信息。
#
CREATE TABLE alias (
address varchar(255) NOT NULL default '',
goto text NOT NULL,
domain varchar(255) NOT NULL default '',
created datetime NOT NULL default '0000-00-00 00:00:00',
modified datetime NOT NULL default '0000-00-00 00:00:00',
active tinyint(1) NOT NULL default '1',
mlist varchar(255) NULL default ‘’, # 新增字段mlist
transport_maps varchar(255) NULL default ‘’, # 新增字段 transport_maps
PRIMARY KEY (address),
KEY address (address)
) TYPE=MyISAM COMMENT='Postfix Admin - Virtual Aliases';

#mysql -u root –p < DATABASE_MYSQL.TXT # root password: testadmin

#vi config.inc.php # 修改 postfixadmin 的設定檔
$CONF['default_language'] = 'tw';
$CONF['database_type'] = 'mysql';
$CONF['database_host'] = 'localhost';
$CONF['database_user'] = 'postfixadmin';
$CONF['database_password'] = 'postfixadmin';
$CONF['database_name'] = 'postfix';
$CONF['encrypt'] = 'md5crypt'; # 用md5 加密密碼
$CONF['domain_path'] = 'YES';
$CONF['domain_in_mailbox'] = 'NO';
$CONF['quota'] = 'YES';
$CONF['alias_control'] = 'YES';
$CONF['footer_text'] = 'Return to mail.test.com';
$CONF['footer_link'] = 'http://mail.test.com/postfixadmin/';

#vi /usr/local/etc/apache22/httpd.conf # 修改 apache 的 User 跟 Group

#User www
#Group www
User vmail
Group vmail

#vi /usr/local/etc/apache22/Includes/mine.conf # 增加 apache 對應的 postfixadmin 虛擬目錄

Alias /postfixadmin/ "/usr/local/www/postfixadmin/"
<Directory "/usr/local/www/postfixadmin">
Options None
AllowOverride ALL
Order allow,deny
Allow from all
</Directory>

#apachectl stop # 重新啟動apache
#apachectl start

由於postfixadmin 本身沒有添加transport_maps選項功能,為了實現添加mail address list記錄到alias 表中需要修改以下幾個文件:
# vi /usr/local/www/postfixadmin/variables.inc.php # 增加如下四個變量
$fTransport_maps = "";
$fMlist = "";
$tMlist = "";
$tTransport_maps = "";

# vi /usr/local/www/postfixadmin/templates/craete-alias.tpl # 加下劃線部分為新增行

<div id="edit_form">
<form name="alias" method="post">
<table>
<tr>
<td colspan="3"><h3><?php print $PALANG['pCreate_alias_welcome']; ?></h3></td>
</tr>
<tr>
<td><?php print $PALANG['pCreate_alias_address']; ?></td>
<td><input class="flat" type="text" name="fAddress" value="<?php print $tAddress; ?>" /></td>
<td>
<select class="flat" name="fDomain">
<?php
for ($i = 0; $i < sizeof ($list_domains); $i++)
{
if ($tDomain == $list_domains[$i])
{
print "<option value=\"$list_domains[$i]\" selected>$list_domains[$i]</option>\n";
}
else
{
print "<option value=\"$list_domains[$i]\">$list_domains[$i]</option>\n";
}
}
?>
</select>
<?php print $pCreate_alias_address_text; ?>
</td>
</tr>
<tr>
<td><?php print $PALANG['pCreate_alias_goto'] . ":"; ?></td>
<td><input class="flat" type="text" name="fGoto" value="<?php print $tGoto; ?>" /></td>
<td><?php print $pCreate_alias_goto_text; ?></td>
</tr>
<tr>
<td><?php print "Mlist" . ":"; ?></td>
<td><input class="flat" type="text" name="fMlist" value="<?php print $tMlist; ?>" /></td>
</tr>
<tr>
<td><?php print "Transport_maps" . ":"; ?></td>
<td><input class="flat" type="text" name="fTransport_maps" value="<?php print $tTransport_maps; ?>" /></td>
</tr>
<tr>
<td colspan="3" class="hlp_center"><input class="button" type="submit" name="submit" value="<?php print $PALANG['pCreate_alias_button']; ?>" /></td>
</tr>
<tr>
<td colspan="3" class="standout"><?php print $tMessage; ?></td>
</tr>
<tr>
<td colspan="3" class="help_text"><?php print $PALANG['pCreate_alias_catchall_text']; ?></td>
</tr>
</table>
</div>

# vi /usr/local/www/postfixadmin/templates/edit-alias.tpl # 加下劃線部分為新增或修改部分

<div id="edit_form">
<form name="alias" method="post">
<table>
<tr>
<td colspan="3"><h3><?php print $PALANG['pEdit_alias_welcome']; ?></h3></td>
</tr>
<tr>
<td><?php print $PALANG['pEdit_alias_address'] . ":"; ?></td>
<td><?php print $fAddress; ?></td>
<td>&nbsp;</td>
</tr>
<tr>
<td><?php print $PALANG['pEdit_alias_goto'] . ":"; ?></td>
<td>
<textarea class="flat" rows="10" cols="60" name="fGoto">
<?php
$array = preg_split ('/,/', $tGoto);
for ($i = 0 ; $i < sizeof ($array) ; $i++)
{
if (empty ($array[$i])) continue;
print "$array[$i]\n";
}
?>
</textarea>
</td>
<td>&nbsp;</td>
</tr>
<tr>
<td><?php print "Mlist" . ":"; ?></td>
<td><input class="flat" type="text" name="fMlist" value="<?php print $tMlist; ?>" /></td>
</tr>
<tr>
<td><?php print "Transport_maps" . ":"; ?></td>
<td><input class="flat" type="text" name="fTransport_maps" value="<?php print $tTransport_maps; ?>" /></td>
</tr>
<tr>
<td colspan="3" class="hlp_center"><input class="button" type="submit" name="submit" value="<?php print $PALANG['pEdit_alias_button']; ?>" /></td>
</tr>
<tr>
<td colspan="3" class="standout"><?php print $tMessage; ?></td>
</tr>
</table>
</form>
</div>

# vi /usr/local/www/postfixadmin/templates/admin_list-virtual.tpl # 加下劃線部分為新增或修改部分
<div id="admin_virtual">
<form name="overview" method="post">
<select name="fDomain" onChange="this.form.submit()";>
<?php
for ($i = 0; $i < sizeof ($list_domains); $i++)
{
if ($fDomain == $list_domains[$i])
{
print "<option value=\"$list_domains[$i]\" selected>$list_domains[$i]</option>\n";
}
else
{
print "<option value=\"$list_domains[$i]\">$list_domains[$i]</option>\n";
}
}
?>
</select>
<input type="hidden" name="limit" value="0">
<input type="submit" name="go" value="<?php print $PALANG['pAdminList_virtual_button']; ?>" />
</form>
<h4><?php print $PALANG['pAdminList_virtual_welcome'] . $fDomain; ?></h4>
<p><?php print $PALANG['pAdminList_virtual_alias_alias_count'] . ": " . $limit['alias_count'] . " / " . $limit['aliases']; ?></p>
<p><?php print $PALANG['pAdminList_virtual_alias_mailbox_count'] . ": " . $limit['mailbox_count'] . " / " . $limit['mailboxes']; ?></p>
<form name="search" method="post" action="search.php">
<input type="textbox" name="search" size="10">
</form>
</div>

<?php
print "<div id=\"nav_bar\">\n";
if ($tDisplay_back_show == 1)
{
print "<a href=\"list-virtual.php?domain=$fDomain&limit=$tDisplay_back\"><img border=\"0\" src=\"../images/arrow-l.png\" title=\"" . $PALANG['pOverview_left_arrow'] . "\" alt=\"" . $PALANG['pOverview_left_arrow'] . "\"></a>\n";
}
if ($tDisplay_up_show == 1)
{
print "<a href=\"list-virtual.php?domain=$fDomain&limit=0\"><img border=\"0\" src=\"../images/arrow-u.png\" title=\"" . $PALANG['pOverview_up_arrow'] . "\" alt=\"" . $PALANG['pOverview_up_arrow'] . "\"></a>\n";
}
if ($tDisplay_next_show == 1)
{
print "<a href=\"list-virtual.php?domain=$fDomain&limit=$tDisplay_next\"><img border=\"0\" src=\"../images/arrow-r.png\" title=\"" . $PALANG['pOverview_right_arrow'] . "\" alt=\"" . $PALANG['pOverview_right_arrow'] . "\"></a>\n";
}
print "</div>\n";

if (sizeof ($tAlias) > 0)
{
print "<table id=\"alias_table\">\n";
print " <tr>\n";
print " <td colspan=\"5\"><h3>" . $PALANG['pOverview_alias_title'] . "</h3></td>";
print " </tr>";
print " <tr class=\"header\">\n";
print " <td>" . $PALANG['pAdminList_virtual_alias_address'] . "</td>\n";
print " <td>" . $PALANG['pAdminList_virtual_alias_goto'] . "</td>\n";
print " <td>Transport_map</td>\n";
print " <td colspan=\"2\">&nbsp;</td>\n";
print " </tr>\n";

for ($i = 0; $i < sizeof ($tAlias); $i++)
{
if ((is_array ($tAlias) and sizeof ($tAlias) > 0))
{
print " <tr class=\"hilightoff\" onMouseOver=\"className='hilighton';\" onMouseOut=\"className='hilightoff';\">\n";
print " <td>" . $tAlias[$i]['address'] . "</td>\n";
print " <td>" . ereg_replace (",", "<br>", $tAlias[$i]['goto']) . "</td>\n";
print " <td>" . $tAlias[$i]['transport_maps'] . "</td>\n";
print " <td><a href=\"edit-alias.php?address=" . urlencode ($tAlias[$i]['address']) . "&domain=$fDomain" . "\">" . $PALANG['edit'] . "</a></td>\n";
print " <td><a href=\"delete.php?table=alias" . "&delete=" . urlencode ($tAlias[$i]['address']) . "&domain=$fDomain" . "\"onclick=\"return confirm ('" . $PALANG['confirm'] . $PALANG['pOverview_get_aliases'] . ": ". $tAlias[$i]['address'] . "')\">" . $PALANG['del'] . "</a></td>\n";
print " </tr>\n";
}
}
print "</table>\n";
}

if (sizeof ($tMailbox) > 0)
{
print "<table id=\"mailbox_table\">\n";
print " <tr>\n";
print " <td colspan=\"7\"><h3>" . $PALANG['pOverview_mailbox_title'] . "</h3></td>";
print " </tr>";
print " <tr class=\"header\">\n";
print " <td>" . $PALANG['pAdminList_virtual_mailbox_username'] . "</td>\n";
print " <td>" . $PALANG['pAdminList_virtual_mailbox_name'] . "</td>\n";
if ($CONF['quota'] == 'YES') print " <td>" . $PALANG['pAdminList_virtual_mailbox_quota'] . "</td>\n";
print " <td>" . $PALANG['pAdminList_virtual_mailbox_modified'] . "</td>\n";
print " <td>" . $PALANG['pAdminList_virtual_mailbox_active'] . "</td>\n";
print " <td colspan=\"2\">&nbsp;</td>\n";
print " </tr>\n";

for ($i = 0; $i < sizeof ($tMailbox); $i++)
{
if ((is_array ($tMailbox) and sizeof ($tMailbox) > 0))
{
print " <tr class=\"hilightoff\" onMouseOver=\"className='hilighton';\" onMouseOut=\"className='hilightoff';\">\n";
print " <td>" . $tMailbox[$i]['username'] . "</td>\n";
print " <td>" . $tMailbox[$i]['name'] . "</td>\n";
if ($CONF['quota'] == 'YES') print " <td>" . $tMailbox[$i]['quota'] / $CONF['quota_multiplier'] . "</td>\n";
print " <td>" . $tMailbox[$i]['modified'] . "</td>\n";
$active = ($tMailbox[$i]['active'] == 1) ? $PALANG['YES'] : $PALANG['NO'];
print " <td><a href=\"edit-active.php?username=" . urlencode ($tMailbox[$i]['username']) . "&domain=$fDomain" . "\">" . $active . "</a></td>\n";
print " <td><a href=\"edit-mailbox.php?username=" . urlencode ($tMailbox[$i]['username']) . "&domain=$fDomain" . "\">" . $PALANG['edit'] . "</a></td>\n";
print " <td><a href=\"delete.php?table=mailbox" . "&delete=" . urlencode ($tMailbox[$i]['username']) . "&domain=$fDomain" . "\"onclick=\"return confirm ('" . $PALANG['confirm'] . $PALANG['pOverview_get_mailboxes'] . ": ". $tMailbox[$i]['username'] . "')\">" . $PALANG['del'] . "</a></td>\n";
print " </tr>\n";
}
}
print "</table>\n";
}
?>

# vi /usr/local/www/postfixadmin/admin/create-alias.php # 加下劃線部分為新增或修改部分
<?php
//
// Postfix Admin
// by Mischa Peters <mischa at high5 dot net>
// Copyright (c) 2002 - 2005 High5!
// License Info: http://www.postfixadmin.com/?file=LICENSE.TXT
//
// File: create-alias.php
//
// Template File: create-alias.tpl
//
// Template Variables:
//
// tMessage
// tAddress
// tGoto
// tDomain
//
// Form POST \ GET Variables:
//
// fAddress
// fGoto
// fDomain
//
require ("../variables.inc.php");
require ("../config.inc.php");
require ("../functions.inc.php");
include ("../languages/" . check_language () . ".lang");

$list_domains = list_domains ();

if ($_SERVER['REQUEST_METHOD'] == "GET")
{
$pCreate_alias_goto_text = $PALANG['pCreate_alias_goto_text'];

if (isset ($_GET['domain'])) $tDomain = escape_string ($_GET['domain']);

include ("../templates/header.tpl");
include ("../templates/admin_menu.tpl");
include ("../templates/create-alias.tpl");
include ("../templates/footer.tpl");
}

if ($_SERVER['REQUEST_METHOD'] == "POST")
{
$pCreate_alias_goto_text = $PALANG['pCreate_alias_goto_text'];

$fAddress = escape_string ($_POST['fAddress']) . "@" . escape_string ($_POST['fDomain']);
$fAddress = strtolower ($fAddress);
$fGoto = escape_string ($_POST['fGoto']);
$fGoto = strtolower ($fGoto);
$fMlist = escape_string ($_POST['fMlist']);
$fMlist = strtolower ($fMlist);
$fTransport_maps = escape_string ($_POST['fTransport_maps']);
$fTransport_maps = strtolower ($fTransport_maps);
$fDomain = escape_string ($_POST['fDomain']);

if (!preg_match ('/@/',$fGoto))
{
$fGoto = $fGoto . "@" . escape_string ($_POST['fDomain']);
}

if (!check_alias ($fDomain))
{
$error = 1;
$tAddress = escape_string ($_POST['fAddress']);
$tGoto = $fGoto;
$tDomain = $fDomain;
$tMlist = $fMlist;
$tTransport_maps = $fTransport_maps;
$pCreate_alias_address_text = $PALANG['pCreate_alias_address_text_error3'];
}

if (empty ($fAddress) or !check_email ($fAddress))
{
$error = 1;
$tAddress = escape_string ($_POST['fAddress']);
$tGoto = $fGoto;
$tMlist = $fMlist;
$tTransport_maps = $fTransport_maps;
$tDomain = $fDomain;
$pCreate_alias_address_text = $PALANG['pCreate_alias_address_text_error1'];
}

if (empty ($fGoto) or !check_email ($fGoto))
{
$error = 1;
$tAddress = escape_string ($_POST['fAddress']);
$tGoto = $fGoto;
$tDomain = $fDomain;
$tMlist = $fMlist;
$tTransport_maps = $fTransport_maps;
$pCreate_alias_goto_text = $PALANG['pCreate_alias_goto_text_error'];
}

if (escape_string ($_POST['fAddress']) == "*") $fAddress = "@" . escape_string ($_POST['fDomain']);

$result = db_query ("SELECT * FROM alias WHERE address='$fAddress'");
if ($result['rows'] == 1)
{
$error = 1;
$tAddress = escape_string ($_POST['fAddress']);
$tGoto = $fGoto;
$tDomain = $fDomain;
$tMlist = $fMlist;
$tTransport_maps = $fTransport_maps;
$pCreate_alias_address_text = $PALANG['pCreate_alias_address_text_error2'];
}

if ($error != 1)
{
if (preg_match ('/^\*@(.*)$/', $fGoto, $match)) $fGoto = "@" . $match[1];

$result = db_query ("INSERT INTO alias (address,goto,domain,created,modified,mlist,transport_maps) VALUES ('$fAddress','$fGoto','$fDomain',NOW(),NOW(),'$fMlist','$fTransport_maps')");
if ($result['rows'] != 1)
{
$tDomain = $fDomain;
$tMessage = $PALANG['pCreate_alias_result_error'] . "<br />($fAddress -> $fGoto)<br />";
}
else
{
db_log ($CONF['admin_email'], $fDomain, "create alias", "$fAddress -> $fGoto");

$tDomain = $fDomain;
$tMessage = $PALANG['pCreate_alias_result_succes'] . "<br />($fAddress -> $fGoto)</br />";
}
}

include ("../templates/header.tpl");
include ("../templates/admin_menu.tpl");
include ("../templates/create-alias.tpl");
include ("../templates/footer.tpl");
}
?>

# vi /usr/local/www/postfixadmin/admin/edit-alias.php # 加下劃線部分為新增或修改部分
<?php
//
// Postfix Admin
// by Mischa Peters <mischa at high5 dot net>
// Copyright (c) 2002 - 2005 High5!
// License Info: http://www.postfixadmin.com/?file=LICENSE.TXT
//
// File: edit-alias.php
//
// Template File: edit-alias.tpl
//
// Template Variables:
//
// tMessage
// tGoto
//
// Form POST \ GET Variables:
//
// fAddress
// fDomain
// fGoto
//
require ("../variables.inc.php");
require ("../config.inc.php");
require ("../functions.inc.php");
include ("../languages/" . check_language () . ".lang");

if ($_SERVER['REQUEST_METHOD'] == "GET")
{
$fAddress = escape_string ($_GET['address']);
$fDomain = escape_string ($_GET['domain']);

$result = db_query ("SELECT * FROM alias WHERE address='$fAddress' AND domain='$fDomain'");
if ($result['rows'] == 1)
{
$row = db_array ($result['result']);
$tGoto = $row['goto'];
$tMlist = $row['mlist'];
$tTransport_maps = $row['transport_maps'];
}
else
{
$tMessage = $PALANG['pEdit_alias_address_error'];
}

include ("../templates/header.tpl");
include ("../templates/admin_menu.tpl");
include ("../templates/edit-alias.tpl");
include ("../templates/footer.tpl");
}

if ($_SERVER['REQUEST_METHOD'] == "POST")
{
$pEdit_alias_goto = $PALANG['pEdit_alias_goto'];

$fAddress = escape_string ($_GET['address']);
$fAddress = strtolower ($fAddress);
$fDomain = escape_string ($_GET['domain']);
$fGoto = escape_string ($_POST['fGoto']);
$fGoto = strtolower ($fGoto);
$fMlist = escape_string ($_POST['fMlist']);
$fMlist = strtolower ($fMlist);
$fTransport_maps = escape_string ($_POST['fTransport_maps']);
$fTransport_maps = strtolower ($fTransport_maps);

if (empty ($fGoto))
{
$error = 1;
$tGoto = $fGoto;
$tMlist = $fMlist;
$tTransport_maps = $fTransport_maps;
$tMessage = $PALANG['pEdit_alias_goto_text_error1'];
}

$goto = preg_replace ('/\\\r\\\n/', ',', $fGoto);
$goto = preg_replace ('/\r\n/', ',', $goto);
$goto = preg_replace ('/[\s]+/i', '', $goto);
$goto = preg_replace ('/\,*$/', '', $goto);
$array = preg_split ('/,/', $goto);

for ($i = 0; $i < sizeof ($array); $i++) {
if (in_array ("$array[$i]", $CONF['default_aliases'])) continue;
if (empty ($array[$i])) continue;
if (!check_email ($array[$i]))
{
$error = 1;
$tGoto = $goto;
$tMlist = $fMlist;
$tTransport_maps = $fTransport_maps;
$tMessage = $PALANG['pEdit_alias_goto_text_error2'] . "$array[$i]</div>";
}
}

if ($error != 1)
{
$result = db_query ("UPDATE alias SET goto='$goto',mlist='$fMlist',transport_maps='$fTransport_maps',modified=NOW() WHERE address='$fAddress' AND domain='$fDomain'");
if ($result['rows'] != 1)
{
$tMessage = $PALANG['pEdit_alias_result_error'];
}
else
{
db_log ($CONF['admin_email'], $fDomain, "edit alias", "$fAddress -> $goto");

header ("Location: list-virtual.php?domain=$fDomain");
exit;
}
}

include ("../templates/header.tpl");
include ("../templates/admin_menu.tpl");
include ("../templates/edit-alias.tpl");
include ("../templates/footer.tpl");
}
?>

# vi /usr/local/www/postfixadmin/admin/list-virtual.php # 加下劃線部分為新增或修改部分
<?php
//
// Postfix Admin
// by Mischa Peters <mischa at high5 dot net>
// Copyright (c) 2002 - 2005 High5!
// License Info: http://www.postfixadmin.com/?file=LICENSE.TXT
//
// File: list-virtual.php
//
// Template File: admin_list-virtual.tpl
//
// Template Variables:
//
// tMessage
// tAlias
// tMailbox
//
// Form POST \ GET Variables:
//
// fDomain
//
require ("../variables.inc.php");
require ("../config.inc.php");
require ("../functions.inc.php");
include ("../languages/" . check_language () . ".lang");

$list_domains = list_domains ();

$tAlias = array();
$tMailbox = array();

if ($_SERVER['REQUEST_METHOD'] == "GET")
{
$fDisplay = 0;
$page_size = $CONF['page_size'];

if (isset ($_GET['domain'])) $fDomain = escape_string ($_GET['domain']);
if (isset ($_GET['limit'])) $fDisplay = escape_string ($_GET['limit']);

if ((is_array ($list_domains) and sizeof ($list_domains) > 0)) if (empty ($fDomain)) $fDomain = $list_domains[0];

$limit = get_domain_properties ($fDomain);

if ((is_array ($list_domains) and sizeof ($list_domains) > 0)) if (empty ($fDomain)) $fDomain = $list_domains[1];

if ($CONF['alias_control'] == "YES")
{
$query = "SELECT alias.address,alias.goto,alias.transport_maps FROM alias WHERE alias.domain='$fDomain' ORDER BY alias.address LIMIT $fDisplay, $page_size";
}
else
{
$query = "SELECT alias.address,alias.goto,alias.transport_maps FROM alias LEFT JOIN mailbox ON alias.address=mailbox.username WHERE alias.domain='$fDomain' AND mailbox.maildir IS NULL ORDER BY alias.address LIMIT $fDisplay, $page_size";
}

$result = db_query ("$query");
if ($result['rows'] > 0)
{
while ($row = db_array ($result['result']))
{
$tAlias[] = $row;
}
}

$result = db_query ("SELECT * FROM mailbox WHERE domain='$fDomain' ORDER BY username LIMIT $fDisplay, $page_size");
if ($result['rows'] > 0)
{
while ($row = db_array ($result['result']))
{
$tMailbox[] = $row;
}
}

if (isset ($limit))
{
if ($fDisplay >= $page_size)
{
$tDisplay_back_show = 1;
$tDisplay_back = $fDisplay - $page_size;
}
if (($limit['alias_count'] > $page_size) or ($limit['mailbox_count'] > $page_size))
{
$tDisplay_up_show = 1;
}
if ((($fDisplay + $page_size) < $limit['alias_count']) or (($fDisplay + $page_size) < $limit['mailbox_count']))
{
$tDisplay_next_show = 1;
$tDisplay_next = $fDisplay + $page_size;
}
}

include ("../templates/header.tpl");
include ("../templates/admin_menu.tpl");
include ("../templates/admin_list-virtual.tpl");
include ("../templates/footer.tpl");
}

if ($_SERVER['REQUEST_METHOD'] == "POST")
{
$fDisplay = 0;
$page_size = $CONF['page_size'];

$fDomain = escape_string ($_POST['fDomain']);
if (isset ($_POST['limit'])) $fDisplay = escape_string ($_POST['limit']);

$limit = get_domain_properties ($fDomain);

if ($CONF['alias_control'] == "YES")
{
$query = "SELECT alias.address,alias.goto,alias.transport_maps FROM alias WHERE alias.domain='$fDomain' ORDER BY alias.address LIMIT $fDisplay, $page_size";
}
else
{
$query = "SELECT alias.address,alias.goto,alias.transport_maps FROM alias LEFT JOIN mailbox ON alias.address=mailbox.username WHERE alias.domain='$fDomain' AND mailbox.maildir IS NULL ORDER BY alias.address LIMIT $fDisplay, $page_size";
}

$result = db_query ("$query");
if ($result['rows'] > 0)
{
while ($row = db_array ($result['result']))
{
$tAlias[] = $row;
}
}

$result = db_query ("SELECT * FROM mailbox WHERE domain='$fDomain' ORDER BY username LIMIT $fDisplay, $page_size");
if ($result['rows'] > 0)
{
while ($row = db_array ($result['result']))
{
$tMailbox[] = $row;
}
}

if (isset ($limit))
{
if ($fDisplay >= $page_size)
{
$tDisplay_back_show = 1;
$tDisplay_back = $fDisplay - $page_size;
}
if (($limit['alias_count'] > $page_size) or ($limit['mailbox_count'] > $page_size))
{
$tDisplay_up_show = 1;
}
if ((($fDisplay + $page_size) < $limit['alias_count']) or (($fDisplay + $page_size) < $limit['mailbox_count']))
{
$tDisplay_next_show = 1;
$tDisplay_next = $fDisplay + $page_size;
}
}

include ("../templates/header.tpl");
include ("../templates/admin_menu.tpl");
include ("../templates/admin_list-virtual.tpl");
include ("../templates/footer.tpl");
}
?>

# vi /usr/local/www/postfixadmin/admin/search.php # 加下劃線部分為新增或修改部分
<?php
//
// Postfix Admin
// by Mischa Peters <mischa at high5 dot net>
// Copyright (c) 2002 - 2005 High5!
// License Info: http://www.postfixadmin.com/?file=LICENSE.TXT
//
// File: search.php
//
// Template File: search.tpl
//
// Template Variables:
//
// tAlias
// tMailbox
//
// Form POST \ GET Variables:
//
// fSearch
//
require ("../variables.inc.php");
require ("../config.inc.php");
require ("../functions.inc.php");
include ("../languages/" . check_language () . ".lang");

$tAlias = array();
$tMailbox = array();

if ($_SERVER['REQUEST_METHOD'] == "GET")
{
if (isset ($_GET['search'])) $fSearch = escape_string ($_GET['search']);

if ($CONF['alias_control'] == "YES")
{
$query = "SELECT alias.address,alias.goto,alias.mlist,alias.transport_maps,alias.modified,alias.domain FROM alias WHERE alias.address LIKE '%$fSearch%' OR alias.goto LIKE '%$fSearch%' ORDER BY alias.address";
}
else
{
$query = "SELECT alias.address,alias.goto,alias.mlist,alias.transport_maps ,alias.modified,alias.domain FROM alias LEFT JOIN mailbox ON alias.address=mailbox.username WHERE alias.address LIKE '%$fSearch%' AND mailbox.maildir IS NULL ORDER BY alias.address";
}

$result = db_query ("$query");

if ($result['rows'] > 0)
{
while ($row = db_array ($result['result']))
{
$tAlias[] = $row;
}
}

$result = db_query ("SELECT * FROM mailbox WHERE username LIKE '%$fSearch%' ORDER BY username");
if ($result['rows'] > 0)
{
while ($row = db_array ($result['result']))
{
$tMailbox[] = $row;
}
}

include ("../templates/header.tpl");
include ("../templates/admin_menu.tpl");
include ("../templates/admin_search.tpl");
include ("../templates/footer.tpl");
}

if ($_SERVER['REQUEST_METHOD'] == "POST")
{
if (isset ($_POST['search'])) $fSearch = escape_string ($_POST['search']);

if ($CONF['alias_control'] == "YES")
{
$query = "SELECT alias.address,alias.goto,alias.mlist,alias.transport_maps,alias.modified,alias.domain FROM alias WHERE alias.address LIKE '%$fSearch%' OR alias.goto LIKE '%$fSearch%' ORDER BY alias.address";
}
else
{
$query = "SELECT alias.address,alias.goto,alias.mlist,alias.transport_maps,lias.modified,alias.domain FROM alias LEFT JOIN mailbox ON alias.address=mailbox.username WHERE alias.address LIKE '%$fSearch%' AND mailbox.maildir IS NULL ORDER BY alias.address";
}

$result = db_query ("$query");

if ($result['rows'] > 0)
{
while ($row = db_array ($result['result']))
{
$tAlias[] = $row;
}
}

$result = db_query ("SELECT * FROM mailbox WHERE username LIKE '%$fSearch%' ORDER BY username");
if ($result['rows'] > 0)
{
while ($row = db_array ($result['result']))
{
$tMailbox[] = $row;
}
}

include ("../templates/header.tpl");
include ("../templates/admin_menu.tpl");
include ("../templates/admin_search.tpl");
include ("../templates/footer.tpl");
}
?>
# vi /usr/local/www/postfixadmin/templates/admin_search.tpl # 加下劃線部分為新增或修改部分
<div id="overview">
<h4><?php print $PALANG['pSearch_welcome'] . $fSearch; ?></h4>
<form name="search" method="post" action="search.php">
<input type="textbox" name="search">
</form>
</div>

<?php
if (sizeof ($tAlias) > 0)
{
print "<table id=\"alias_table\">\n";
print " <tr>\n";
print " <td colspan=\"5\"><h3>".$PALANG['pOverview_alias_title']."</h3></td>";
print " </tr>";
print " <tr class=\"header\">\n";
print " <td>" . $PALANG['pOverview_alias_address'] . "</td>\n";
print " <td>" . $PALANG['pOverview_alias_goto'] . "</td>\n";
print " <td>Mlist</td>\n";
print " <td>Transport_maps</td>\n";
print " <td>" . $PALANG['pOverview_alias_modified'] . "</td>\n";
print " <td colspan=\"2\">&nbsp;</td>\n";
print " </tr>\n";

for ($i = 0; $i < sizeof ($tAlias); $i++)
{
if ((is_array ($tAlias) and sizeof ($tAlias) > 0))
{
print " <tr class=\"hilightoff\" onMouseOver=\"className='hilighton';\" onMouseOut=\"className='hilightoff';\">\n";
print " <td>" . $tAlias[$i]['address'] . "</td>\n";
print " <td>" . ereg_replace (",", "<br>", $tAlias[$i]['goto']) . "</td>\n";
print " <td>" . $tAlias[$i]['mlist'] . "</td>\n";
print " <td>" . $tAlias[$i]['transport_maps'] . "</td>\n";
print " <td>" . $tAlias[$i]['modified'] . "</td>\n";
print " <td><a href=\"edit-alias.php?address=" . urlencode ($tAlias[$i]['address']) . "&domain=" . $tAlias[$i]['domain'] . "\">" . $PALANG['edit'] . "</a></td>\n";
print " <td><a href=\"delete.php?table=alias&delete=" . urlencode ($tAlias[$i]['address']) . "&domain=" . $tAlias[$i]['domain'] . "\"onclick=\"return confirm ('" . $PALANG['confirm'] . $PALANG['pOverview_get_aliases'] . ": ". $tAlias[$i]['address'] . "')\">" . $PALANG['del'] . "</a></td>\n";
print " </tr>\n";
}
}

print "</table>\n";
}

if (sizeof ($tMailbox) > 0)
{
print "<table id=\"mailbox_table\">\n";
print " <tr>\n";
print " <td colspan=\"7\"><h3>".$PALANG['pOverview_mailbox_title']."</h3></td>";
print " </tr>";
print " <tr class=\"header\">\n";
print " <td>" . $PALANG['pOverview_mailbox_username'] . "</td>\n";
print " <td>" . $PALANG['pOverview_mailbox_name'] . "</td>\n";
if ($CONF['quota'] == 'YES') print " <td>" . $PALANG['pOverview_mailbox_quota'] . "</td>\n";
print " <td>" . $PALANG['pOverview_mailbox_modified'] . "</td>\n";
print " <td>" . $PALANG['pOverview_mailbox_active'] . "</td>\n";
print " <td colspan=\"2\">&nbsp;</td>\n";
print " </tr>\n";

for ($i = 0; $i < sizeof ($tMailbox); $i++)
{
if ((is_array ($tMailbox) and sizeof ($tMailbox) > 0))
{
print " <tr class=\"hilightoff\" onMouseOver=\"className='hilighton';\" onMouseOut=\"className='hilightoff';\">\n";
print " <td>" . $tMailbox[$i]['username'] . "</td>\n";
print " <td>" . $tMailbox[$i]['name'] . "</td>\n";
if ($CONF['quota'] == 'YES') print " <td>" . $tMailbox[$i]['quota'] / $CONF['quota_multiplier'] . "</td>\n";
print " <td>" . $tMailbox[$i]['modified'] . "</td>\n";
$active = ($tMailbox[$i]['active'] == 1) ? $PALANG['YES'] : $PALANG['NO'];
print " <td><a href=\"edit-active.php?username=" . urlencode ($tMailbox[$i]['username']) . "&domain=" . $tMailbox[$i]['domain'] . "\">" . $active . "</a></td>\n";
print " <td><a href=\"edit-mailbox.php?username=" . urlencode ($tMailbox[$i]['username']) . "&domain=" . $tMailbox[$i]['domain'] . "\">" . $PALANG['edit'] . "</a></td>\n";
print " <td><a href=\"delete.php?table=mailbox&delete=" . urlencode ($tMailbox[$i]['username']) . "&domain=" . $tMailbox[$i]['domain'] . "\"onclick=\"return confirm ('" . $PALANG['confirm'] . $PALANG['pOverview_get_mailboxes'] . ": ". $tMailbox[$i]['username'] . "')\">" . $PALANG['del'] . "</a></td>\n";
print " </tr>\n";
}
}
print "</table>\n";
}
?>

Setp 5.

安装Courier-imap+maildrop
官方網站 http://www.courier-mta.org
#cd /usr/ports/mail/courier-imap
#make WITH_MYSQL=yes install clean
Options for courier-imap 4.1.x # 選了 AUTH_MYSQL,OpenSSl
[X] AUTH_MYSQL MySQL support
[X] OPENSSL
#chmod +x /var/run/authdaemond
#cd /usr/local/etc/courier-imap
#cp imapd.cnf.dist imapd.cnf
#cp pop3d.cnf.dist pop3d.cnf

#vi /usr/local/etc/authlib/authdaemonrc # 刪除其他的 authxxxx 只留下 authmysql

authmodulelist="authmysql"
authmodulelistorig="authmysql"

#vi /usr/local/etc/authlib/authmysqlrc # 注意:在這個文件中不能使用空白鍵,只能用 tab 鍵,localhost 也不能使用單引號。

MYSQL_SERVER localhost
MYSQL_SOCKET /tmp/mysql.sock
MYSQL_DATABASE postfix
MYSQL_USERNAME postfix
MYSQL_PASSWORD postfix
MYSQL_USER_TABLE mailbox
MYSQL_LOGIN_FIELD username
MYSQL_CRYPT_PWFIELD password # 採用md5加密密碼
MYSQL_UID_FIELD '5001'
MYSQL_GID_FIELD '5001'
MYSQL_HOME_FIELD '/var/mailbox/'
MYSQL_MAILDIR_FIELD maildir
MYSQL_NAME_FIELD name
MYSQL_QUOTA_FIELD quota
MYSQL_WHERE_CLAUSE active='1'

#vi /etc/rc.conf # 建立開機自動啟動

courier_authdaemond_enable="YES"
courier_imap_pop3d_enable="YES"
courier_imap_imapd_enable="YES"

安裝 maildrop
如果采用postfix 的virtual則不用安裝
#cd /usr/ports/mail/maildrop # 安裝 maildrop
#make WITH_AUTHLIB=yes install clean
Options for maildrop 2.0.x # 只選了 AUTH_MYSQL
[X] AUTH_MYSQL MySQL support

因為 maildrop 没有建立 maildir 及刪除maildir 的功能,所以要自己建立兩個shell script 執行(maildirmake.sh ,maildirdel.sh),如果采用virtual做transport,virtual可以自動創建郵箱。
#vi /usr/sbin/maildirmake.sh # 建立新的 /usr/sbin/maildirmake.sh 文件

#!/bin/sh
MailDir=”/var/mailbox”
umask 077
mkdir –p “$MailDir/$1”
/usr/local/bin/maildirmake “$MailDir/$1/$2”

#chmod 755 /usr/sbin/maildirmake.sh

#vi /usr/sbin/maildirdel.sh # 該腳本將會刪除用戶的郵箱目錄及目錄下的所有郵件。
#!/bin/sh
rm –rf /var/mailbox/$1/$2
#chmod 755 /usr/sbin/maildirdel.sh

#vi /usr/local/www/postfixadmin/admin/create-mailbox.php # 更改 create-mailbox.php 文件,在此文件的第 200 行後加入下面這一行:

system("/usr/sbin/maildirmake.sh $fDomain ".$_POST['fUsername']);

#vi /usr/local/www/postfixadmin/create-mailbox.php # 同樣也必須要更改 postfixadmin 目錄下的create-mailbox.php 文件,於 210 行後加入下面這行,其作用為讓網域管理員也可新增使用者。

system("/usr/sbin/maildirmake.sh $fDomain ".$_POST['fUsername']);
更改postfixadmin目錄及postfixadmin/admin目錄下的delete.php文件
在$result = db_query ("SELECT * FROM mailbox WHERE username='$fDelete' AND domain='$fDomain'");行後加幾行(在50或90幾行處):
# vi /var/www/postfixadmin/admin/delete.php (vi /var/www/postfixadmin/delete.php)
$userarray=explode("@",$fDelete);
$user=$userarray[0];
$domain=$userarray[1];
system("/usr/sbin/maildirdel.sh $domain $user");
注意:
如果采用virtual 投遞郵件則可以省去以上步驟(到安裝maildrop部分),maildrop也可以不用安裝。
如果沒有安裝maildrop,新建域後需要在/usr/mailbox/下手動新建以域名命名的文件夾,郵箱則由virtual自動創建。
#/usr/local/sbin/authdaemond start # 手動啟動 authdaemond
#ps -ax |grep authdaemond # 確認 authdaemond 有 up

55665 p0 S 0:00.03 /usr/local/libexec/courier-authlib/authdaemond
55666 p0 S 0:00.00 /usr/local/libexec/courier-authlib/authdaemond


#/usr/local/libexec/courier-imap/imapd.rc start # 手動啟動 imap 服務
#/usr/local/libexec/courier-imap/pop3d.rc start # 手動啟動 pop3 服務
#netstat -na |grep LISTEN # 確認 110 跟 143 port 有 up

tcp4 0 0 *.110 *.* LISTEN
tcp4 0 0 *.143 *.* LISTEN

Setp 6.

初步測試 Postfixadmin + Postfix + MySQL
http://192.168.2.130/postfixadmin/setup.php # 查看 Postfixadmin 的 php 環境有無ok

Postfix Admin Setup Checker 1.0.0
Running software:

- PHP version 5.1.4
- Apache/2.2.2 (FreeBSD) PHP/5.1.4
Checking for dependencies:
- Magic Quotes: ON
- Depends on: presence config.inc.php - OK
- Depends on: MySQL 3.23, 4.0 - OK
- Depends on: MySQL 5.x - OK
- Depends on: session - OK
- Depends on: pcre - OK

#cd /usr/local/www/postfixadmin/
#mv setup.php setup_backup.php # 將 setup.php 刪除或改名稱

http://192.168.2.130/postfixadmin/admin/ # 預設帳號密碼為 admin /admin,進入後即可建立新網域及帳號來測試,建立test.com 網域及 test@test.com 帳號,密碼為test,如下圖:
注意
Mlist:只有不是本機地址才需要填寫
Transport_maps: 只有不是本機地址才需要填寫
例如:從深圳office (B mail server) 發送郵件到guangzhou@test.com (A mail server)這個地址,在B mail server 上的mlist,transports_maps設置如下:
Mlist:guangzhou@test.com
Transport_maps:smtp:A.test.com(或者直接輸入ip地址)

如果是本地server的地址,則Mlist,Transport部分不用輸入任何記錄,說明該地址郵件由本地server進行投遞。

#telnet 127.0.0.1 25 # 測試 25 port 看看 postfix 運行有無正常
Trying 127.0.0.1...
Connected to localhost.test.com.
Escape character is '^]'.
220 mail.test.com ESMTP "Version not Available"
mail from:test@test.com
250 Ok
rcpt to:test@test.com
250 Ok
data
354 End data with <CR><LF>.<CR><LF>
Subject:test
1234
.
250 Ok: queued as 4ED91C5124
quit
221 Bye
Connection closed by foreign host.

#telnet 127.0.0.1 110 # 測試 110 port 看看 pop3 有無正常運作
Trying 127.0.0.1...
Connected to localhost.test.com.
Escape character is '^]'.
+OK Hello there.
user test@test.com
+OK Password required.
pass xxxxx
+OK logged in.
list
+OK POP3 clients that break here, they violate STD53.
.
quit
+OK Bye-bye.
Connection closed by foreign host.

檢查 MySQL 資料庫內容
#mysql -u root p # 查看 MySQL 資料庫
mysql>SHOW DATABASES; # 查看 MySQL 有那些資料庫,注意 ”;” 結尾

+ ---------- +
| Database |
+ ---------- +
| mysql |
| postfix |
| test |
+ ---------- +

mysql>USE mysql; # 進入 mysql 資料庫
Database changed
mysql>SHOW TABLES; # 查看 mysql 這個資料庫裡有多少個資料表

+ ----------------- +
| Tables_in_mysql |
+ ----------------- +
| columns_priv |
| db |
| func |
| host |
| tables_priv |
| user |
+ ----------------- +

mysql>DESC db; # 可查看 db 資料表型態
mysql>SELECT * FROM db; # 可查看 db 資料表內所插入的所, 有內容
mysql>SELECT * FROM user; # 可查看 user 資料表內所插入的所有內容

mysql>USE postfix; # 切換到 postfix 資料庫
Database changed
mysql>SHOW TABLES; # 查看 postfix 資料庫中的所有資料表

+ ------------------- +
| Tables_in_postfix |
+ ------------------- +
| admin |
| alias |
| domain |
| domain_admins |
| log |
| mailbox |
| vacation |
+ ------------------- +

mysql>SELECT * FROM domain; # 查看 domain 資料表內的資料

Setp 7.

安裝 Squirrelmail ( WebMail )
官方網站http://www.squirrlmail.org
#cd /usr/ports/mail/squirrelmail/ # 安裝松鼠 webmail 的主程式,外掛程式需獨立安裝。安裝路徑為:/usr/ports/mail/squirrelmail-*
#make install clean
#vi /usr/local/etc/php.ini # 修改 php.ini

file_uploads = On
session.auto_start = 1

#vi /usr/local/etc/apache22/Includes/mine.conf # 再加入 squirrelmail 的路徑到 apache 網頁目錄

Alias /squirrelmail/ "/usr/local/www/squirrelmail/"
<Directory "/usr/local/www/squirrelmail">
Options None
AllowOverride AuthConfig
Order allow,deny
Allow from all
</Directory>

#apachectl restart # 重新啟動 apache
#chown -R vmail:vmail /var/spool/squirrelmail

#cd /usr/local/www/squirrelmail # 修改 configure 設定值
#./configure
選 10. Languages

1. Default Language : 的 en_US 改成 zh_TW。
2. Default Charset : 改成 big5
Command >> Q
You have not saved your data.
Save? [Y/n]: Y

#vi /usr/local/www/squirrelmail/config/config.php # 手動修改 config.php 檔
$domain = 'test.com';


防病毒防垃圾部分

1 修改postfix設定
#vi /usr/local/etc/postfix/main.conf
c
# ClamAV
content_filter = smtp-amavis:[127.0.0.1]:10024

#vi /usr/local/etc/postfix/master.conf
在最後添加如下內容
smtp-amavis unix - - n - 2 smtp
-o smtp_data_done_timeout=1200
-o disable_dns_lookups=yes
127.0.0.1:10025 inet n - n - - smtpd
-o content_filter=
-o local_recipient_maps=
-o relay_recipient_maps=
-o smtpd_restriction_classes=
-o mynetworks=127.0.0.0/8
-o smtpd_client_restrictions=
-o smtpd_helo_restrictions=
-o smtpd_sender_restrictions=
-o smtpd_recipient_restrictions=permit_mynetworks,reject
-o smtpd_error_sleep_time=0
-o smtpd_soft_error_limit=1001
-o smtpd_hard_error_limit=1000
-o strict_rfc821_envelopes=yes

#vi /usr/local/etc/postfix/aliases
virusalert: root
spamalert: root
2. Amavisd-new:
官方網站 http://ww.ijs.si
安裝 amavisd-new
# cd /usr/ports/security/amavisd-new
# make install clean
選中 mysql
在rc.conf 中加入:amavisd_enable=”YES”
設定檔說明:
Amavisd-new 於 FreeBSD 中的設定檔位置在 /usr/local/etc/amavisd.conf 裡,開機啟動為
#vi /etc/rc.conf 中加入 amavisd_enable="YES" 即可。
隔離的信件將會被存在 /var/virusmails 目錄中。

/usr/local/etc/amavisd.conf 說明:
D_PASS:不做任何處理,直接傳送給收件者。
D_DISCARD:信件不會傳送給寄件者及收件者。
D_BOUNCE:不傳送給收件者,除了定義在 $viruses_that_fake_sender_re 病毒名稱外的信件,amavisd-new 皆會傳送 DSN 訊息給寄件者。
D_REJECT:不傳送給收件者,寄件者會收到拒絕傳送的訊息。
$sa_auto_whitelist = 1; # 啟用自動學習白名單 White List
$sa_mail_body_size_limit = 200*1024; # 超過某個特定大小的郵件就不經過 SpamAssassin 的掃瞄。
$sa_tag_level_deflt = 4.0; # 超過這個分數標準者,才視為垃圾郵件打分數。
$sa_tag2_level_deflt = 6.3; # 超過這個分數標準者,才允許在郵件標頭加入 Spam 資訊。

$sa_kill_level_deflt = 10 ; # 超過這個標準者,就直接將信件備份後刪除。

實際設定:

#vi /usr/local/etc/amavisd.conf

$MYHOME = '/var/amavis';
$mydomain = 'test.com';
$daemon_user = 'vscan';
$daemon_group = 'vscan';

$log_level = 0;

$DO_SYSLOG = 0; # 由 1 改 0

$sa_spam_subject_tag = '***SPAM*** ';
$sa_spam_modifies_subj = 1;

$virus_admin = "virusalert\@$mydomain";
$spam_admin = "spamalert\@$mydomain";
$mailfrom_notify_admin = "virusalert\@$mydomain";
$mailfrom_notify_recip = "virusalert\@$mydomain";
$mailfrom_notify_spamadmin = "spamalert\@$mydomain";

$inet_socket_bind = '127.0.0.1';
$forward_method = 'smtp:127.0.0.1:10025';

$notify_method = $forward_method;
$inet_socket_port = 10024;
$max_servers = 2;

$final_virus_destiny = D_BOUNCE; # (defaults to D_DISCARD)
$final_banned_destiny = D_BOUNCE; # (defaults to D_BOUNCE)
$final_spam_destiny = D_BOUNCE; # (defaults to D_BOUNCE)
$final_bad_header_destiny = D_PASS; # (defaults to D_PASS)

[qr’^\. (zip|rar|arc|arj|zoo|) $’ =>0]

['Clam Antivirus-clamd',

\&ask_daemon, ["CONTSCAN {}\n", '/tmp/clamd'],
qr/\bOK$/, qr/\bFOUND$/,
  
qr/^.*?: (?!InfectedArchive)(.*) FOUND$/ ],

3. SpamAssassin:
官方網站 http://spamassassin.apache.org

安裝SpamAssassin
一般在安裝amavisd-new時會一起安裝。
開機啟動為
#vi /etc/rc.conf 中加入 spamd_enable="YES" 即可。

# cd /usr/lports/mail/p5-Mail-SpamAssassin
# make install clean
可選擇全部選項
設定檔說明:
設定檔位置在/usr/local/etc/mail/spamassassin/local.cf 。預設spamd 會監聽TCP 783 這個 Port。

#vi /usr/local/etc/mail/spamassassin/local.cf

# Whether to change the subject of suspected spam. 在垃圾郵件上之標題上加上註記.
rewrite_header Subject ****SPAM(_SCORE_)****

# Encapsulate spam in an attachment.
# 要如何處理垃圾郵件。因為郵件還會經過防毒程式的處理,所以必須設定為 0。
# 0:將資訊寫入郵件表頭。
# 1:將垃圾郵件轉為附件。
# 2:將垃圾郵件轉為純文字附件。
report_safe 0

# Enable the Bayes system. 使用貝氏學習系統
use_bayes 1
#得分超過10分視為垃圾郵件。
required_score 10
# Enable Bayes auto-learning. 開起貝氏自動學習功能
bayes_auto_learn 1

下載中文垃圾郵件過濾規則Chinese_rules.cf
# cd /usr/local/share/spamassassin/
# fetch http://www.ccert.edu.cn/spam/sa/Chinese_rules.cf
# killall -1 spamd
測試病毒掃描
給該test@test.com用戶發送郵件,包含以下內容:
X5O!P%@AP[4\PZX54(P^)7CC)7}$EICAR-STANDARD-ANTIVIRUS-TEST-FILE!$H+H*
查看日誌 /var/log/maillog,如果出現類似如下提示,則表明成功
Aug 9 15:12:35 mail2 postfix/pipe[1814]: BFF9452118: to=<test@test.com>, orig_to=<virusalert@test.com>, relay=maildrop, delay=0.26, dela
ys=0.15/0.03/0/0.08, dsn=2.0.0, status=sent (delivered via maildrop service)
Aug 9 15:12:35 mail2 postfix/qmgr[530]: BFF9452118: removed
郵件病毒掃描日誌將被記錄在/var/log/clamav/clamav.log中!

測試垃圾郵件掃描
給test@testdept.vicp.n用戶發送郵件,包含以下內容:
XJS*C4JDBQADN1.NSBN3*2IDNEN*GTUBE-STANDARD-ANTI-UBE-TEST-EMAIL*C.34X
查看日誌 /var/log/maillog ,如果出現類似如下提示,表明成功

Aug 9 15:52:23 mail2 postfix/qmgr[530]: BEB5552118: from=<spamalert@testdept.vi
cp.net>, size=3694, nrcpt=2 (queue active)
>, relay=127.0.0.1[127.0.0.1]:10024, delay=152, delays=0.63/0.06/0.03/151, dsn=2
.5.0, status=sent (250 2.5.0 Ok, id=01434-10, BOUNCE)
Aug 9 15:52:23 mail2 postfix/qmgr[530]: D9A4752117: removed

4. ClamAV:
官方網站 http://www.clamav.net

安裝 clamav
# cd /usr/ports/security/clamav
# make install clean
選中 CURL
設定檔說明
位置 /usr/local/etc/clamd.conf
開機啟動 #vi /etc/rc.conf
clamav_clamd_enable="YES"
clamav_freshclam_enable="YES" #freshclam 會每兩個小時會跟ClamAntiVirus Server check
一次有無新病毒碼可更新。
#vi /usr/local/etc/clamd.conf

LogFile /var/log/clamav/clamd.log
LogFileMaxSize 2M
LogTime
LogSyslog
LogVerbose
PidFile /var/run/clamav/clamd.pid
LocalSocket /var/run/clamav/clamd
StreamSaveToDisk
MaxDirectoryRecursion 20
User clamav
AllowSupplementaryGroups
ScanMail
ScanArchive
ScanRAR
ArchiveMaxFileSize 15M
ArchiveMaxRecursion 8
ArchiveMaxFiles 1500
ClamukoScanOnOpen
ClamukoScanOnClose
ClamukoScanOnExec
ClamukoIncludePath /home
ClamukoMaxFileSize 1M

重新啟動postfix:
# postfix stop
# postfix start
# postfix check

啟動 amavisd
# /usr/local/etc/rc.d/amavisd start

# netstat –an |grep LISTEN
127.0.0.1.10024 *.* 0 0 49152 0 LISTEN
127.0.0.1.10025 *.* 0 0 49152 0 LISTEN

功能補充
增加postfixadmin告假自動回信功能
1 #vi /usr/local/www/postfixadmin/config.inc.php
$CONF['vacation'] = 'YES'; # 開啟vacation功能
$CONF['vacation_domain'] = 'autoreply.sz.com'; # 該域名不用真實域名,可任意取
2 新增帳號:vacation
# vipw
vacation:*:65501:65501::0:0:Virtual Vacation:/nonexistent:/sbin/nologin #新增帳號 vacation
#vi /etc/group
vacation:*:65501: #新增組 vacation
3 創建目錄 /var/spool/vacation,只容許"vacation"用戶訪問。vacation.pl腳本及其日誌檔等將放在這裏。
# mkdir /var/spool/vacation
4 將 /usr/local/www/postfixadmin/VIRTUAL_VACATION/vacation.pl拷貝到剛才創建的文件夾中
# cp vacation.pl /var/spool/vacation/vacation.pl
# chown -R vacation:vacation /var/spool/vacation
# chmod 700 /var/spool/vacation/vacation.pl
# ls –al /var/spool/vacation
-rwx------ 1 vacation vacation 3356 Dec 21 00:00 vacation.pl*
5 修改 vacation.pl
將if (do_cache ($email, $orig_from)) { return; } 這句註銷。

6 在master.cf中定義transport 的類型:
#vi /etc/postfix/master.cf: #在最後面增加
# Vacation Autoreplay

vacation unix - n n - - pipe
flags=Rq user=vacation argv=/var/spool/vacation/vacation.pl -f ${sender} -- ${recipient}#


在mail.cf 中設定一個 transport maps file 采用hash資料庫
#vi /etc/postfix/main.cf
transport_maps = mysql:/usr/local/etc/postfix/mysql_virtual_transport_maps.cf hash:/usr/local/etc/postfix/vacation #下劃線部分為新增,以上兩行其實為一行

在/usr/local/etc/postfix/vacation 檔中添加一條新的解析記錄
#vi /usr/local/etc/postfix/vacation
autoreply.sz.com vacation
注意:"autoreply.sz.com"此處與config.inc.php文件中的 $CONF['vacation_domain']的參數相同
"vacation"要與master.cf 中的 "vacation" 相同

# postmap /usr/local/etc/postfix/vacation # 創建hash資料庫
執行 "postfix reload" 完成配置

HTTPS與 OpenSSL 設定
安裝openssl
#cd /usr/ports/security/openssl
#make install clean
在 Apache 22中,預設安裝即支援 SSL,只需產生一組金鑰,並設定啟動 SSL 即可。
1 產生金鑰
# cd /usr/local/etc/
# mkdir CA #建立存放根證書目錄
# cd CA
# openssl genrsa –des3 -out ca.key 1024 #生成ca.key,並給ca.key設置密碼。
# openssl req -new -key ca.key -out ca.req #生成ca.req證書申請。
You are about to be asked to enter information that will be incorporated
into your certificate request.
What you are about to enter is what is called a Distinguished Name or a DN.
There are quite a few fields but you can leave some blank
For some fields there will be a default value,
If you enter '.', the field will be left blank.
-----
Country Name (2 letter code) [AU]:CN
State or Province Name (full name) [Some-State]:GD
Locality Name (eg, city) []:SZ
Organization Name (eg, company) [Internet Wiszits Pty Ltd]:TEST.COM
Organizational Unit Name (eg, section) []:SZ CA
Common Name (eg, YOUR name) []:TEST
Email Address []:test@test.com

Please enter the following 'extra' attributes
to be sent with your certificate request
A challenge password []:按 Enter 即可
An optional company name []:按 Enter 即可

# openssl x509 -req -days 3650 -signkey ca.key -in ca.req -out ca.pem
在第二個 openssl 指令中必須輸入一些基本資訊,最後產生一個有效期限 3650 天(10年)的憑證。接著,必須產生 Apache 伺服器用的憑證:
# openssl genrsa -out httpd.key 1024 #httpd.key不要設置密碼,否則每次重啟httpd服務都需要輸入密碼。
所以不用加‘-des3’參數。
# openssl req -new -key httpd.key -out httpd.req
You are about to be asked to enter information that will be incorporated
into your certificate request.
What you are about to enter is what is called a Distinguished Name or a DN.
There are quite a few fields but you can leave some blank
For some fields there will be a default value,
If you enter '.', the field will be left blank.
-----
Country Name (2 letter code) [AU]:CN
State or Province Name (full name) [Some-State]:GD
Locality Name (eg, city) []:SZ
Organization Name (eg, company) [Internet Wiszits Pty Ltd]:TEST.COM
Organizational Unit Name (eg, section) []:Web Server
Common Name (eg, YOUR name) []:192.168.2.130
Email Address []:test@test.com

Please enter the following 'extra' attributes
to be sent with your certificate request
A challenge password []:按 Enter 即可
An optional company name []:按 Enter 即可

# openssl x509 -req -days 3650 -CA ca.pem -CAkey ca.key -in httpd.req -out httpd.pem
同樣的,必須輸入關於這個憑證的一些資料,最後,使用之前所產生的憑證ca.pem簽發一個有效期限 3650 天的伺服器用憑證。必須注意的是,在 Common Name 必須輸入您的主機名稱,以避免連線時憑證名稱和網頁名稱不符的警告。另外,在產生憑證時,當 OpenSSL 要求輸入用來保護憑證的密碼時,都沒有輸入密碼。如果輸入密碼,則以後 Apache 要啟動時都必須輸入密碼才可以啟動。
# chmod 400 /usr/local/etc/CA/*
證書申請文件可以刪除
# rm -rf *.req
設定及啟動 HTTPS
修改 /usr/local/etc/apache22/httpd.conf 打開選項
Include etc/apache22/extra/httpd-ssl.conf
修改 /usr/local/etc/apache22/extra/httpd-ssl.conf 以設定 SSL,請先找到下列區段:
<VirtualHost _default_:443>
# General setup for the virtual host
DocumentRoot “/usr/local/www/apache22/data”
ServerName 192.168.2.130:443
ServerAdmin test@test.com
ErrorLog /var/log/httpd-error.log
TransferLog /var/log/httpd-access.log
.......
SSLCertificateFile /usr/local/etc/CA/httpd.pem
......
SSLCertificateKeyFile /usr/local/etc/CA/httpd.key
在 /etc/rc.conf 中加入 Apache SSL 的設定:
Apache22ssl_enable="YES"
重新啟動 Apache 即可:
# /usr/local/etc/rc.d/apache22.sh restart
Postfix smtpd 加入TLS支持
1 先生成smtp.pem證書
# cd /usr/local/etc/CA
# openssl genrsa -out smtpd.key 1024
# openssl req -new -key smtpd.key -out smtpd.req #輸入相關信息
# openssl x509 -req -days 3650 -CA ca.pem -CAkey ca

# openssl x509 -req -days 3650 -CA ca.pem -CAkey ca.key -in smtpd.req -out smptd.pem
#cat smtpd.key smtpd.pem > smtp.pem #將smtpd.key 和smtpd.pem合成一個文件smtp.pem
2 修改 main.cf
#vi /usr/local/etc/postfix/main.cf #在最後加入以下內容
smtp_use_tls = yes
smtpd_use_tls = yes
smtp_tls_note_starttls_offer = yes
smtpd_tls_key_file = /usr/local/etc/CA/smtp.pem
smtpd_tls_cert_file = /usr/local/etc/CA/smtp.pem
smtpd_tls_CAfile = /usr/local/etc/CA/smtp.pem
smtpd_tls_loglevel = 1
smtpd_tls_received_header = yes
mtpd_tls_session_cache_timeout = 3600s
tls_random_source = dev:/dev/urandom
#postfix reload
3 測試 
#telnet loadlhost 25 # 測試是否啟動 TLS 加密,手動輸入 STARTTLS 如果出現:”220 Ready to start TLS” 表示TLS已經成功啟動。

Trying ::1...
telnet: connect to address ::1: Connection refused
Trying 127.0.0.1...
Connected to mail.test.com
Escape character is '^]'.
220 mail.test.com ESMTP “SZ Mail System”
ehlo localhost
250-mail.test.com
250-PIPELINING
250-SIZE 10240000
250-VRFY
250-ETRN
250-STARTTLS
250-AUTH LOGIN PLAIN DIGEST-MD5 CRAM-MD5
250-AUTH=LOGIN PLAIN DIGEST-MD5 CRAM-MD5
250-ENHANCEDSTATUSCODES
250 8BITMIME
250 DSN
STARTTLS
220 2.0.0 Ready to start TLS
quit
quit
221 Bye
Connection closed by foreign host.
# 在postfix啟用TLS後SMTP端口還是用25。

POP3 和 IMAP 加密
#cd /usr/local/etc/courier-imap
#vi pop3d.cnf # 設定 POP3s 995 port 金鑰產生設定檔

RANDFILE = /usr/local/share/courier-imap/pop3d.rand

[ req ]
default_bits = 1024
encrypt_key = yes
distinguished_name = req_dn
x509_extensions = cert_type
prompt = no

[ req_dn ]
C=CN
ST=GD
L=SZ
O=TEST.COM
OU=SZ POP3
CN=localhost
emailAddress=test@test.com

[ cert_type ]
nsCertType = server

#vi imapd.cnf # 設定 IMAPs 993 port 金鑰產生設定檔

RANDFILE = /usr/local/share/courier-imap/imapd.rand

[ req ]
default_bits = 1024
encrypt_key = yes
distinguished_name = req_dn
x509_extensions = cert_type
prompt = no

[ req_dn ]
C=CN
ST=GD
L=SZ
O=TEST.COM
OU=SZ IMAP
CN=localhost
emailAddress=test@test.com

[ cert_type ]
nsCertType = server


#/usr/local/sbin/mkimapdcert # 開始產生安全認證的金鑰 imapd.pem 及 pop3d.pem 檔,放置於#/usr/local/sbin/mkpop3dcert # /usr/local/share/courier-iamp 下,證書默認有效期為一年,可修改
# /usr/local/share/courier-imap/下的mkimapdcert 和mkpop3dcert 文件
# 把365改成3650(十年)。

#vi /etc/rc.conf # 設定開機啟動

courier_imap_imapd_ssl_enable="YES"
courier_imap_pop3d_ssl_enable="YES"

#/usr/local/etc/rc.d/courier-imap-pop3d-ssl.sh start # 啟動 pop3s
#/usr/local/etc/rc.d/courier-imap-imapd-ssl.sh start # 啟動 imaps

# sockstat -l4 # 確定開啟的服務 port

USER COMMAND PID FD PROTO LOCAL ADDRESS FOREIGN ADDRESS
root couriertcp 59481 3 tcp4 *:993 *:* # imaps
root couriertcp 59470 3 tcp4 *:995 *:* # pop3s

增加fetchmail功能
#cd /usr/ports/mail/fetchmail
# make install clean #安裝fetchmail
# vi /etc/rc.conf #增加fetchmain開機啟動
fetchmail_enable=”YES”
# vi /usr/local/etc/fetchmailrc #配置fetchmail
set syslog
set postmaster "test"
poll pop3.163.com proto POP3
envelope Devlivered-To
user "test@163.com" with password "xxxxxxx" is test@test.com no keep

意思就是使用系統log,Postmaster為test (主要是投遞發生錯誤時回信的from位址)
Mail server是 pop3.163.com
在收到的郵件中加Develivered-To標籤.
郵件帳戶是test@163.com,密碼是xxxxxx,轉發給test@test.com
不用在mail伺服器上保留郵件.

相关文章 热门文章
  • 微软推出新功能 提高Hotmail密码安全性
  • Hotmail新功能:“我的朋友可能被黑了”
  • 谷歌已着手整合数项Gmail/Google+功能
  • 新型电子邮件服务Shortmail获75万美元种子资金
  • Gmail事件启示:特大规模云计算不见得是好事
  • 恶意入侵者利用Gmail等发起精准性攻击
  • 谷歌禁止13岁以下儿童使用Gmail邮箱
  • Gmail推出可切换的多种收件箱模式
  • 继gmail之后谷歌购买并新注多个邮件域
  • 岁月催人老 微软Hotmail已经15岁了
  • 邮件系统双雄PK: TurboMail vs Exchange
  • TurboMail如何搭建与外网通信的局域网邮件服务器
  • Install and configure Postfix with Cyrus-SASL+Cyr...
  • 在FreeBSD上建立一个功能完整的邮件服务器
  • postfix 邮件病毒过滤
  • 在Fedora上建立自己的邮件服务器
  • Postfix + SpamAssassin 安裝手冊
  • Postfix + Courier-IMAP + Cyrus-SASL + MySQL + IMP...
  • Postfix + Cyrus-SASL + Cyrus-IMAPD + PgSQL HOWTO
  • 在FreeBSD5.1簡單安裝Postfix+Qpopper+Openwebmail
  • 在RHEL 4 上配置全功能的Postfix 服务器
  • Postfix + Cyrus-IMAP + Cyrus-SASL + MySQL + IMP 完..
  • 我的POSTFIX安装笔记
  • Postfix电子邮局的配置步骤
  • 自由广告区
     
    最新软件下载
  • SharePoint Server 2010 部署文档
  • Exchange 2010 RTM升级至SP1 教程
  • Exchange 2010 OWA下RBAC实现的组功能...
  • Lync Server 2010 Standard Edition 标..
  • Lync Server 2010 Enterprise Edition...
  • Forefront Endpoint Protection 2010 ...
  • Lync Server 2010 Edge 服务器部署文档
  • 《Exchange 2003专家指南》
  • Mastering Hyper-V Deployment
  • Windows Server 2008 R2 Hyper-V
  • Microsoft Lync Server 2010 Unleashed
  • Windows Server 2008 R2 Unleashed
  • 今日邮件技术文章
  • 腾讯,在创新中演绎互联网“进化论”
  • 华科人 张小龙 (中国第二代程序员 QQ...
  • 微软推出新功能 提高Hotmail密码安全性
  • 快压技巧分享:秒传邮件超大附件
  • 不容忽视的邮件营销数据分析过程中的算..
  • 国内手机邮箱的现状与未来发展——访尚..
  • 易观数据:2011Q2中国手机邮箱市场收入..
  • 穿越时空的爱恋 QQ邮箱音视频及贺卡邮件
  • Hotmail新功能:“我的朋友可能被黑了”
  • 入侵邻居网络发骚扰邮件 美国男子被重..
  • 网易邮箱莫子睿:《非你莫属》招聘多过..
  • 中国电信推广189邮箱绿色账单
  • 最新专题
  • 鸟哥的Linux私房菜之Mail服务器
  • Exchange Server 2010技术专题
  • Windows 7 技术专题
  • Sendmail 邮件系统配置
  • 组建Exchange 2003邮件系统
  • Windows Server 2008 专题
  • ORF 反垃圾邮件系统
  • Exchange Server 2007 专题
  • ISA Server 2006 教程专题
  • Windows Vista 技术专题
  • “黑莓”(BlackBerry)专题
  • Apache James 专题
  • 分类导航
    邮件新闻资讯:
    IT业界 | 邮件服务器 | 邮件趣闻 | 移动电邮
    电子邮箱 | 反垃圾邮件|邮件客户端|网络安全
    行业数据 | 邮件人物 | 网站公告 | 行业法规
    网络技术:
    邮件原理 | 网络协议 | 网络管理 | 传输介质
    线路接入 | 路由接口 | 邮件存储 | 华为3Com
    CISCO技术 | 网络与服务器硬件
    操作系统:
    Windows 9X | Linux&Uinx | Windows NT
    Windows Vista | FreeBSD | 其它操作系统
    邮件服务器:
    程序与开发 | Exchange | Qmail | Postfix
    Sendmail | MDaemon | Domino | Foxmail
    KerioMail | JavaMail | Winwebmail |James
    Merak&VisNetic | CMailServer | WinMail
    金笛邮件系统 | 其它 |
    反垃圾邮件:
    综述| 客户端反垃圾邮件|服务器端反垃圾邮件
    邮件客户端软件:
    Outlook | Foxmail | DreamMail| KooMail
    The bat | 雷鸟 | Eudora |Becky! |Pegasus
    IncrediMail |其它
    电子邮箱: 个人邮箱 | 企业邮箱 |Gmail
    移动电子邮件:服务器 | 客户端 | 技术前沿
    邮件网络安全:
    软件漏洞 | 安全知识 | 病毒公告 |防火墙
    攻防技术 | 病毒查杀| ISA | 数字签名
    邮件营销:
    Email营销 | 网络营销 | 营销技巧 |营销案例
    邮件人才:招聘 | 职场 | 培训 | 指南 | 职场
    解决方案:
    邮件系统|反垃圾邮件 |安全 |移动电邮 |招标
    产品评测:
    邮件系统 |反垃圾邮件 |邮箱 |安全 |客户端
    广告联系 | 合作联系 | 关于我们 | 联系我们 | 繁體中文
    版权所有:邮件技术资讯网©2003-2010 www.5dmail.net, All Rights Reserved
    www.5Dmail.net Web Team   粤ICP备05009143号