使用 Postfix、Courier、MySQL 和 SquirrelMail (Ubuntu 13.10) 的虚拟用户和域使用 Postfix、Courier、MySQL 和 SquirrelMail (Ubuntu 13.10) 的虚拟用户和域使用 Postfix、Courier、MySQL 和 SquirrelMail (Ubuntu 13.10) 的虚拟用户和域使用 Postfix、Courier、MySQL 和 SquirrelMail (Ubuntu 13.10) 的虚拟用户和域
  • 文章
  • 正则表达式
    • 工具
  • 登录
找到的结果: {phrase} (显示: {results_count} 共: {results_count_total})
显示: {results_count} 共: {results_count_total}

加载更多搜索结果...

搜索范围
模糊匹配
搜索标题
搜索内容
发表 admin at 2025年2月28日
类别
  • 未分类
标签

使用 Postfix、Courier、MySQL 和 SquirrelMail (Ubuntu 13.10) 的虚拟用户和域

本教程适用于这些操作系统版本

  • Ubuntu 13.10(Saucy Salamander)
  • Ubuntu 11.04(Natty Narwhal)

在此页

  1. 1 条初步说明 <李>
  2. 2 安装 Postfix、Courier、Saslauthd、MySQL、phpMyAdmin
  3. 3 将配额补丁应用到 Postfix
  4. 4 为 Postfix/Courier 创建 MySQL 数据库
  5. 5 配置后缀
  6. 6 配置 Saslauthd
  7. 7 配置信使
  8. 8 修改/etc/aliases
  9. 9 安装 amavisd-new、SpamAssassin 和 ClamAV
  10. 10 安装 Razor、Pyzor 和 DCC 并配置 SpamAssassin

本教程的版权 (c) 2014 归 Falko Timme 和 Srijan Kishore 所有。它源自 Christoph Haas 的教程,您可以在 http://workaround.org 找到该教程。您可以根据 Creative Commons 许可证 2.5 或任何更高版本免费使用本教程。

本文档介绍如何安装基于虚拟用户和域(即 MySQL 数据库中的用户和域)的 Postfix 邮件服务器。我还将演示 Courier(Courier-POP3、Courier-IMAP)的安装和配置,以便 Courier 可以针对 Postfix 使用的同一 MySQL 数据库进行身份验证。

生成的 Postfix 服务器能够支持 SMTP-AUTH 和 TLS 以及配额(默认情况下配额没有内置到 Postfix 中,我将展示如何适当地修补你的 Postfix)。密码以加密形式存储在数据库中(我发现的大多数文档都处理纯文本密码,这存在安全风险)。除此之外,本教程还介绍了 Amavisd、SpamAssassin 和 ClamAV 的安装,以便扫描电子邮件中的垃圾邮件和病毒。我还将展示如何将 SquirrelMail 安装为网络邮件界面,以便用户可以阅读和发送电子邮件以及更改密码。

这种“虚拟”设置(MySQL 数据库中的虚拟用户和域)的优点是它比基于“真实”系统用户的设置性能更高。使用此虚拟设置,您的邮件服务器可以处理数以千计的域和用户。此外,它更易于管理,因为您只需在添加新用户/域或编辑现有用户/域时处理 MySQL 数据库。不再有 postmap 命令来创建 db 文件,不再重新加载 Postfix 等。对于 MySQL 数据库的管理,您可以使用基于 Web 的工具,如 phpMyAdmin,它也将安装在本指南中。第三个好处是用户有一个电子邮件地址作为用户名(而不是用户名+电子邮件地址),这更容易理解和记住。

本指南旨在作为实用指南;它不包括理论背景。它们在网络上的许多其他文档中得到处理。

本文档不提供任何形式的保证!我想说的是,这不是建立这样一个系统的唯一方法。有很多方法可以实现这个目标,但这是我采用的方法。我不保证这对你有用!

1 初步说明

本教程基于 Ubuntu 13.10 Server (Saucy Salamander),因此在继续本教程之前,您应该设置基本的 Ubuntu 13.10 服务器安装。系统应该有一个静态 IP 地址。我在本教程中使用 192.168.0.100 作为我的 IP 地址,使用 server1.example.com 作为主机名。

确保您以 root 身份登录(键入

sudo su

成为 root),因为我们必须以 root 用户身份运行本教程中的所有步骤。

使 /bin/sh 成为 /bin/bash 的符号链接非常重要...

dpkg-reconfigure dash

使用 dash 作为默认系统 shell (/bin/sh)? <-- 没有

...并且您禁用了 AppArmor:

/etc/init.d/apparmor stop 
update-rc.d -f apparmor remove
apt-get remove apparmor apparmor-utils

2 安装 Postfix、Courier、Saslauthd、MySQL、phpMyAdmin

要安装 Postfix、Courier、Saslauthd、MySQL 和 phpMyAdmin,我们只需运行

apt-get install postfix postfix-mysql postfix-doc mysql-client mysql-server courier-authdaemon courier-authlib-mysql courier-pop courier-pop-ssl courier-imap courier-imap-ssl libsasl2-2 libsasl2-modules libsasl2-modules-sql sasl2-bin libpam-mysql openssl phpmyadmin apache2 libapache2-mod-php5 php5 php5-mysql libpam-smbpass

你会被问到几个问题:

MySQL \root\ 用户的新密码:<-- yourrootsqlpassword
重复 MySQL \root\ 用户的密码:<-- yourrootsqlpassword
为基于 Web 的管理创建目录? <-- 否
一般邮件配置类型:<-- Internet Site
系统邮件名称: <-- server1.example.com
需要 SSL 证书 <-- 确定
Web 服务器重新配置自动:<-- apache2
使用 dbconfig-common 为 phpmyadmin 配置数据库? <-- 没有

3 将配额补丁应用到 Postfix

我们必须获取 Postfix 源代码,使用配额补丁对其进行修补,构建新的 Postfix .deb 包并安装这些 .deb 包:

apt-get build-dep postfix
cd /usr/src
apt-get source postfix

(确保在以下命令中使用正确的 Postfix 版本。我安装了 Postfix 2.10.2。您可以通过运行找到您的 Postfix 版本

postconf -d | grep mail_version

输出应如下所示:

:/usr/src#
wget http://vda.sourceforge.net/VDA/postfix-vda-v13-2.10.0.patch
cd postfix-2.10.2
patch -p1 < ../postfix-vda-v13-2.10.0.patch

接下来打开 debian/rules 并将 DEB_BUILD_HARDENING 从 1 更改为 0:

vi debian/rules
[...]
export DEB_BUILD_HARDENING=0
[...]

如果您不这样做,您的构建将失败并显示以下错误消息:

maildir.c: In function âdeliver_maildirâ:
maildir.c:974:17: error: format not a string literal and no format arguments [-Werror=format-security]
maildir.c:977:17: error: format not a string literal and no format arguments [-Werror=format-security]
maildir.c:983:17: error: format not a string literal and no format arguments [-Werror=format-security]
maildir.c:986:17: error: format not a string literal and no format arguments [-Werror=format-security]
maildir.c: In function âsql2fileâ:
maildir.c:404:25: warning: ignoring return value of âreadâ, declared with attribute warn_unused_result [-Wunused-result]
maildir.c:417:26: warning: ignoring return value of âwriteâ, declared with attribute warn_unused_result [-Wunused-result]
cc1: some warnings being treated as errors
make: *** [maildir.o] Error 1
make: Leaving directory `/usr/src/postfix-2.10.2/src/virtual'
make[1]: *** [update] Error 1
make[1]: Leaving directory `/usr/src/postfix-2.10.2'
make: *** [build] Error 2
dpkg-buildpackage: error: debian/rules build gave error exit status 2
:/usr/src/postfix-2.10.2#

现在我们可以构建新的 Postfix .deb 包:

dpkg-buildpackage

现在我们向上一个目录,那就是创建新的 .deb 包的地方:

cd ..

命令

ls -l

向您显示可用的包:

:/usr/src# ls -l
total 7124
drwxr-xr-x 18 root root    4096 Apr 16 04:29 postfix-2.10.2
-rw-r--r--  1 root root   48594 Apr 16 04:29 postfix-cdb_2.10.2-1_amd64.deb
-rw-r--r--  1 root root  161974 Apr 16 04:29 postfix-dev_2.10.2-1_all.deb
-rw-r--r--  1 root root 1094344 Apr 16 04:29 postfix-doc_2.10.2-1_all.deb
-rw-r--r--  1 root root   57342 Apr 16 04:29 postfix-ldap_2.10.2-1_amd64.deb
-rw-r--r--  1 root root   50554 Apr 16 04:29 postfix-mysql_2.10.2-1_amd64.deb
-rw-r--r--  1 root root   50804 Apr 16 04:29 postfix-pcre_2.10.2-1_amd64.deb
-rw-r--r--  1 root root   50756 Apr 16 04:29 postfix-pgsql_2.10.2-1_amd64.deb
-rw-r--r--  1 root root   55701 Jun  7  2013 postfix-vda-v13-2.10.0.patch
-rw-r--r--  1 root root  282175 Apr 16 04:28 postfix_2.10.2-1.diff.gz
-rw-r--r--  1 root root    1522 Apr 16 04:28 postfix_2.10.2-1.dsc
-rw-r--r--  1 root root    3899 Apr 16 04:29 postfix_2.10.2-1_amd64.changes
-rw-r--r--  1 root root 1542368 Apr 16 04:29 postfix_2.10.2-1_amd64.deb
-rw-r--r--  1 root root 3828326 Sep 12  2013 postfix_2.10.2.orig.tar.gz

选择 postfix 和 postfix-mysql 包并像这样安装它们:

dpkg -i postfix_2.10.2-1_amd64.deb postfix-mysql_2.10.2-1_amd64.deb

4 为 Postfix/Courier 创建 MySQL 数据库

现在我们创建一个名为邮件的数据库:

mysqladmin -u root -p create mail

你会被问到这个问题:

输入密码:<-- yourrootsqlpassword

接下来,我们进入 MySQL shell:

mysql -u root -p

在 MySQL shell 上,我们使用密码 mail_admin_password(替换为您自己的密码)创建用户 mail_admin,该用户对邮件数据库具有 SELECT、INSERT、UPDATE、DELETE 权限。 Postfix 和 Courier 将使用此用户连接到邮件数据库:

GRANT SELECT, INSERT, UPDATE, DELETE ON mail.* TO 'mail_admin'@'localhost' IDENTIFIED BY 'mail_admin_password';
GRANT SELECT, INSERT, UPDATE, DELETE ON mail.* TO 'mail_admin'@'localhost.localdomain' IDENTIFIED BY 'mail_admin_password';
FLUSH PRIVILEGES;

仍然在 MySQL shell 上,我们创建 Postfix 和 Courier 所需的表:

USE mail;
CREATE TABLE domains (
domain varchar(50) NOT NULL,
PRIMARY KEY (domain) )
ENGINE=MyISAM;
CREATE TABLE forwardings (
source varchar(80) NOT NULL,
destination TEXT NOT NULL,
PRIMARY KEY (source) )
ENGINE=MyISAM;
CREATE TABLE users (
email varchar(80) NOT NULL,
password varchar(20) NOT NULL,
quota INT(10) DEFAULT '10485760',
PRIMARY KEY (email)
) ENGINE=MyISAM;
CREATE TABLE transport (
domain varchar(128) NOT NULL default '',
transport varchar(128) NOT NULL default '',
UNIQUE KEY domain (domain)
) ENGINE=MyISAM;
quit;

正如您可能已经注意到的那样,随着退出;命令我们已经离开了 MySQL shell 并回到了 Linux shell。

domains 表将存储 Postfix 应该为其接收电子邮件的每个虚拟域(例如 example.com)。

domain
example.com

forwardings 表用于将一个电子邮件地址别名为另一个电子邮件地址,例如为 [email 转发电子邮件。

source destination
[email  [email 

users 表存储所有虚拟用户(即电子邮件地址,因为电子邮件地址和用户名相同)和密码(以加密形式!)和每个邮箱的配额值(在此示例中,默认值为 10485760 字节,即 10MB)。

email password quota
[email  No9.E4skNvGa. ("secret" in encrypted form) 10485760

transport 表是可选的,它是为高级用户准备的。它允许将单个用户、整个域或所有邮件的邮件转发到另一台服务器。例如,

domain transport
example.com smtp:[1.2.3.4]

将通过 smtp 协议将 example.com 的所有电子邮件转发到 IP 地址为 1.2.3.4 的服务器(方括号 [ ] 的意思是“不要查找 MX DNS 记录”(这对 IP 地址有意义...)。如果您使用完全限定的域名 (FQDN),则不会使用方框括号。)。

顺便说一句,(我假设您的邮件服务器系统的 IP 地址是 192.168.0.100)您可以在浏览器中通过 http://192.168.0.100/phpmyadmin/ 访问 phpMyAdmin 并以 mail_admin 身份登录。然后你可以看看数据库。稍后您可以使用 phpMyAdmin 来管理您的邮件服务器。

5 配置后缀

现在我们必须告诉 Postfix 在哪里可以找到数据库中的所有信息。因此我们必须创建六个文本文件。您会注意到我告诉 Postfix 在 IP 地址 127.0.0.1 而不是 localhost 上连接到 MySQL。这是因为 Postfix 在 chroot jail 中运行,并且无法访问 MySQL 套接字,如果我告诉 Postfix 使用 localhost,它会尝试连接该套接字。如果我使用 127.0.0.1 Postfix 使用 TCP 网络连接到 MySQL,即使在 chroot jail 中也没有问题(另一种方法是将 MySQL 套接字移动到 chroot jail 中,这会导致一些其他问题)。

请确保 /etc/mysql/my.cnf 包含以下行:

vi /etc/mysql/my.cnf
[...]
# Instead of skip-networking the default is now to listen only on
# localhost which is more compatible and is not less secure.
bind-address           = 127.0.0.1
[...]

如果你不得不修改/etc/mysql/my.cnf,请现在重启MySQL:

/etc/init.d/mysql restart

跑步

netstat -tap | grep mysql

确保 MySQL 正在侦听 127.0.0.1 (localhost.localdomain):

:~#

现在让我们创建六个文本文件。

vi /etc/postfix/mysql-virtual_domains.cf
user = mail_admin
password = mail_admin_password
dbname = mail
query = SELECT domain AS virtual FROM domains WHERE domain='%s'
hosts = 127.0.0.1
vi /etc/postfix/mysql-virtual_forwardings.cf
user = mail_admin
password = mail_admin_password
dbname = mail
query = SELECT destination FROM forwardings WHERE source='%s'
hosts = 127.0.0.1
vi /etc/postfix/mysql-virtual_mailboxes.cf
user = mail_admin
password = mail_admin_password
dbname = mail
query = SELECT CONCAT(SUBSTRING_INDEX(email,'@',-1),'/',SUBSTRING_INDEX(email,'@',1),'/') FROM users WHERE email='%s'
hosts = 127.0.0.1
vi /etc/postfix/mysql-virtual_email2email.cf
user = mail_admin
password = mail_admin_password
dbname = mail
query = SELECT email FROM users WHERE email='%s'
hosts = 127.0.0.1
vi /etc/postfix/mysql-virtual_transports.cf
user = mail_admin
password = mail_admin_password
dbname = mail
query = SELECT transport FROM transport WHERE domain='%s'
hosts = 127.0.0.1
vi /etc/postfix/mysql-virtual_mailbox_limit_maps.cf
user = mail_admin
password = mail_admin_password
dbname = mail
query = SELECT quota FROM users WHERE email='%s'
hosts = 127.0.0.1

然后更改这些文件的权限和组:

chmod o= /etc/postfix/mysql-virtual_*.cf
chgrp postfix /etc/postfix/mysql-virtual_*.cf

现在我们创建一个名为 vmail 的用户和组,主目录为 /home/vmail。这是存储所有邮箱的地方。

groupadd -g 5000 vmail
useradd -g vmail -u 5000 vmail -d /home/vmail -m

接下来我们做一些 Postfix 配置。确保用有效的 FQDN 替换 server1.example.com,否则你的 Postfix 可能无法正常工作!

postconf -e 'myhostname = server1.example.com'
postconf -e 'mydestination = server1.example.com, localhost, localhost.localdomain'
postconf -e 'mynetworks = 127.0.0.0/8'
postconf -e 'virtual_alias_domains ='
postconf -e 'virtual_alias_maps = proxy:mysql:/etc/postfix/mysql-virtual_forwardings.cf, mysql:/etc/postfix/mysql-virtual_email2email.cf'
postconf -e 'virtual_mailbox_domains = proxy:mysql:/etc/postfix/mysql-virtual_domains.cf'
postconf -e 'virtual_mailbox_maps = proxy:mysql:/etc/postfix/mysql-virtual_mailboxes.cf'
postconf -e 'virtual_mailbox_base = /home/vmail'
postconf -e 'virtual_uid_maps = static:5000'
postconf -e 'virtual_gid_maps = static:5000'
postconf -e 'smtpd_sasl_auth_enable = yes'
postconf -e 'broken_sasl_auth_clients = yes'
postconf -e 'smtpd_sasl_authenticated_header = yes'
postconf -e 'smtpd_recipient_restrictions = permit_mynetworks, permit_sasl_authenticated, reject_unauth_destination'
postconf -e 'smtpd_use_tls = yes'
postconf -e 'smtpd_tls_cert_file = /etc/postfix/smtpd.cert'
postconf -e 'smtpd_tls_key_file = /etc/postfix/smtpd.key'
postconf -e 'transport_maps = proxy:mysql:/etc/postfix/mysql-virtual_transports.cf'
postconf -e 'virtual_maildir_extended = yes'
postconf -e 'virtual_mailbox_limit_maps = proxy:mysql:/etc/postfix/mysql-virtual_mailbox_limit_maps.cf'
postconf -e 'virtual_mailbox_limit_override = yes'
postconf -e 'virtual_maildir_limit_message = "The user you are trying to reach is over quota."'
postconf -e 'virtual_overquota_bounce = yes'
postconf -e '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'

之后我们创建 TLS 所需的 SSL 证书:

cd /etc/postfix
openssl req -new -outform PEM -out smtpd.cert -newkey rsa:2048 -nodes -keyout smtpd.key -keyform PEM -days 365 -x509

国家名称(2 个字母代码)[AU]:<-- 输入您的国家名称(例如,\DE\)。
州或省名称(全名)[Some-State]:<-- 输入您的州或省名称。
地点名称(例如,城市)[]:<-- 输入您的城市。
组织名称(例如,公司)[Internet Widgits Pty Ltd]:<-- 输入您的组织名称(例如,您公司的名称)。
组织单位名称(例如,部门)[]:<-- 输入您的组织单位名称(例如 \IT 部门\)。
通用名称(例如,您的name) []: <-- 输入系统的完全限定域名(例如 \server1.example.com\)。
电子邮件地址 []: <-- 输入您的电子邮件地址。

然后更改 smtpd.key 的权限:

chmod o= /etc/postfix/smtpd.key

6 配置 Saslauthd

第一次运行

mkdir -p /var/spool/postfix/var/run/saslauthd

然后编辑 /etc/default/saslauthd.将 START 设置为 yes 并将行 OPTIONS=\-c -m /var/run/saslauthd\ 更改为 OPTIONS=\-c -m /var/spool/postfix/var/run/saslauthd -r\:

vi /etc/default/saslauthd
#
# Settings for saslauthd daemon
# Please read /usr/share/doc/sasl2-bin/README.Debian for details.
#

# Should saslauthd run automatically on startup? (default: no)
START=yes

# Description of this saslauthd instance. Recommended.
# (suggestion: SASL Authentication Daemon)
DESC="SASL Authentication Daemon"

# Short name of this saslauthd instance. Strongly recommended.
# (suggestion: saslauthd)
NAME="saslauthd"

# Which authentication mechanisms should saslauthd use? (default: pam)
#
# Available options in this Debian package:
# getpwent  -- use the getpwent() library function
# kerberos5 -- use Kerberos 5
# pam       -- use PAM
# rimap     -- use a remote IMAP server
# shadow    -- use the local shadow password file
# sasldb    -- use the local sasldb database file
# ldap      -- use LDAP (configuration is in /etc/saslauthd.conf)
#
# Only one option may be used at a time. See the saslauthd man page
# for more information.
#
# Example: MECHANISMS="pam"
MECHANISMS="pam"

# Additional options for this mechanism. (default: none)
# See the saslauthd man page for information about mech-specific options.
MECH_OPTIONS=""

# How many saslauthd processes should we run? (default: 5)
# A value of 0 will fork a new process for each connection.
THREADS=5

# Other options (default: -c -m /var/run/saslauthd)
# Note: You MUST specify the -m option or saslauthd won't run!
#
# WARNING: DO NOT SPECIFY THE -d OPTION.
# The -d option will cause saslauthd to run in the foreground instead of as
# a daemon. This will PREVENT YOUR SYSTEM FROM BOOTING PROPERLY. If you wish
# to run saslauthd in debug mode, please run it by hand to be safe.
#
# See /usr/share/doc/sasl2-bin/README.Debian for Debian-specific information.
# See the saslauthd man page and the output of 'saslauthd -h' for general
# information about these options.
#
# Example for chroot Postfix users: "-c -m /var/spool/postfix/var/run/saslauthd"
# Example for non-chroot Postfix users: "-c -m /var/run/saslauthd"
#
# To know if your Postfix is running chroot, check /etc/postfix/master.cf.
# If it has the line "smtp inet n - y - - smtpd" or "smtp inet n - - - - smtpd"
# then your Postfix is running in a chroot.
# If it has the line "smtp inet n - n - - smtpd" then your Postfix is NOT
# running in a chroot.
#OPTIONS="-c -m /var/run/saslauthd"
OPTIONS="-c -m /var/spool/postfix/var/run/saslauthd -r"

然后创建文件/etc/pam.d/smtp。它应该只包含以下两行(确保填写正确的数据库详细信息):

vi /etc/pam.d/smtp
auth    required   pam_mysql.so user=mail_admin passwd=mail_admin_password host=127.0.0.1 db=mail table=users usercolumn=email passwdcolumn=password crypt=1
account sufficient pam_mysql.so user=mail_admin passwd=mail_admin_password host=127.0.0.1 db=mail table=users usercolumn=email passwdcolumn=password crypt=1

接下来创建文件 /etc/postfix/sasl/smtpd.conf。它应该是这样的:

vi /etc/postfix/sasl/smtpd.conf
pwcheck_method: saslauthd
mech_list: plain login
allow_plaintext: true
auxprop_plugin: sql
sql_engine: mysql
sql_hostnames: 127.0.0.1
sql_user: mail_admin
sql_passwd: mail_admin_password
sql_database: mail
sql_select: select password from users where email = '%[email %r'

接下来将 postfix 用户添加到 sasl 组(这确保 Postfix 具有访问 saslauthd 的权限):

adduser postfix sasl

然后重启 Postfix 和 Saslauthd:

/etc/init.d/postfix restart
/etc/init.d/saslauthd restart

7 配置快递

现在我们必须告诉 Courier 它应该针对我们的 MySQL 数据库进行身份验证。首先,编辑 /etc/courier/authdaemonrc 并更改 authmodulelist 的值,使其显示为:

vi /etc/courier/authdaemonrc
[...]
authmodulelist="authmysql"
[...]

然后备份 /etc/courier/authmysqlrc 并清空旧文件:

cp /etc/courier/authmysqlrc /etc/courier/authmysqlrc_orig
cat /dev/null > /etc/courier/authmysqlrc

然后打开 /etc/courier/authmysqlrc 并将以下行放入其中:

vi /etc/courier/authmysqlrc
MYSQL_SERVER localhost
MYSQL_USERNAME mail_admin
MYSQL_PASSWORD mail_admin_password
MYSQL_PORT 0
MYSQL_DATABASE mail
MYSQL_USER_TABLE users
MYSQL_CRYPT_PWFIELD password
#MYSQL_CLEAR_PWFIELD password
MYSQL_UID_FIELD 5000
MYSQL_GID_FIELD 5000
MYSQL_LOGIN_FIELD email
MYSQL_HOME_FIELD "/home/vmail"
MYSQL_MAILDIR_FIELD CONCAT(SUBSTRING_INDEX(email,'@',-1),'/',SUBSTRING_INDEX(email,'@',1),'/')
#MYSQL_NAME_FIELD
MYSQL_QUOTA_FIELD quota

在安装过程中,IMAP-SSL 和 POP3-SSL 的 SSL 证书是使用主机名 localhost 创建的。要将其更改为正确的主机名(本教程中的 server1.example.com),请删除证书...

cd /etc/courier
rm -f /etc/courier/imapd.pem
rm -f /etc/courier/pop3d.pem

...并修改以下两个文件;将 CN=localhost 替换为 CN=server1.example.com(如有必要,您还可以修改其他值):

vi /etc/courier/imapd.cnf
[...]
CN=server1.example.com
[...]
vi /etc/courier/pop3d.cnf
[...]
CN=server1.example.com
[...]

然后重新创建证书...

mkimapdcert
mkpop3dcert

...并重新启动 Courier:

/etc/init.d/courier-authdaemon restart
/etc/init.d/courier-imap restart
/etc/init.d/courier-imap-ssl restart
/etc/init.d/courier-pop restart
/etc/init.d/courier-pop-ssl restart

通过运行

telnet localhost pop3

您可以查看您的 POP3 服务器是否正常工作。它应该返回 +OK 你好。 (键入 quit 返回 Linux shell。)

[电子邮件受保护]:/etc/courier#

8 修改/etc/aliases

现在我们应该打开 /etc/aliases。确保 postmaster 指向 root 并且 root 指向您自己的用户名或您的电子邮件地址,例如像这样:

vi /etc/aliases
[...]
postmaster: root
root: [email 
[...]

或者像这样(如果管理员是你自己的用户名):

[...]
postmaster: root
root:   administrator
[...]

每当您修改 /etc/aliases 时,您必须运行

newaliases

之后并重新启动 Postfix:

/etc/init.d/postfix restart

9 安装 amavisd-new、SpamAssassin 和 ClamAV

要安装 amavisd-new、spamassassin 和 clamav,请运行以下命令:

apt-get install amavisd-new spamassassin clamav clamav-daemon zoo unzip bzip2 libnet-ph-perl libnet-snpp-perl libnet-telnet-perl nomarch lzop pax

之后我们必须配置 amavisd-new。配置被拆分成多个文件,这些文件位于 /etc/amavis/conf.d 目录中。逐一查看以熟悉配置。大多数设置都很好,但是我们必须修改三个文件:

首先,我们必须通过取消注释 @bypass_virus_checks_maps 和 @bypass_spam_checks_maps 行,在 /etc/amavis/conf.d/15-content_filter_mode 中启用 ClamAV 和 SpamAssassin:

vi /etc/amavis/conf.d/15-content_filter_mode

该文件应如下所示:

use strict;

# You can modify this file to re-enable SPAM checking through spamassassin
# and to re-enable antivirus checking.

#
# Default antivirus checking mode
# Please note, that anti-virus checking is DISABLED by
# default.
# If You wish to enable it, please uncomment the following lines:


@bypass_virus_checks_maps = (
   \%bypass_virus_checks, \@bypass_virus_checks_acl, \$bypass_virus_checks_re);


#
# Default SPAM checking mode
# Please note, that anti-spam checking is DISABLED by
# default.
# If You wish to enable it, please uncomment the following lines:


@bypass_spam_checks_maps = (
   \%bypass_spam_checks, \@bypass_spam_checks_acl, \$bypass_spam_checks_re);

1;  # ensure a defined return

然后您应该查看 /etc/amavis/conf.d/20-debian_defaults 中的垃圾邮件设置和垃圾邮件/病毒邮件的操作。如果默认设置适合您,则无需更改任何内容。该文件包含许多解释,因此无需在此处解释设置:

vi /etc/amavis/conf.d/20-debian_defaults
[...]
$QUARANTINEDIR = "$MYHOME/virusmails";
$quarantine_subdir_levels = 1; # enable quarantine dir hashing

$log_recip_templ = undef;    # disable by-recipient level-0 log entries
$DO_SYSLOG = 1;              # log via syslogd (preferred)
$syslog_ident = 'amavis';    # syslog ident tag, prepended to all messages
$syslog_facility = 'mail';
$syslog_priority = 'debug';  # switch to info to drop debug output, etc

$enable_db = 1;              # enable use of BerkeleyDB/libdb (SNMP and nanny)
$enable_global_cache = 1;    # enable use of libdb-based cache if $enable_db=1

$inet_socket_port = 10024;   # default listening socket

$sa_spam_subject_tag = '***SPAM*** ';
$sa_tag_level_deflt  = 2.0;  # add spam info headers if at, or above that level
$sa_tag2_level_deflt = 6.31; # add 'spam detected' headers at that level
$sa_kill_level_deflt = 6.31; # triggers spam evasive actions
$sa_dsn_cutoff_level = 10;   # spam level beyond which a DSN is not sent
[...]
$final_virus_destiny      = D_DISCARD;  # (data not lost, see virus quarantine)
$final_banned_destiny     = D_BOUNCE;   # D_REJECT when front-end MTA
$final_spam_destiny       = D_BOUNCE;
$final_bad_header_destiny = D_PASS;     # False-positive prone (for spam)
[...]

最后,编辑 /etc/amavis/conf.d/50-user 并添加行 $pax=pax;在中间:

vi /etc/amavis/conf.d/50-user
use strict;

#
# Place your configuration directives here.  They will override those in
# earlier files.
#
# See /usr/share/doc/amavisd-new/ for documentation and examples of
# the directives you can use in this file
#
$pax='pax';

#------------ Do not modify anything below this line -------------
1;  # ensure a defined return

然后,运行这些命令将 clamav 用户添加到 amavis 组并重新启动 amavisd-new 和 ClamAV:

adduser clamav amavis
/etc/init.d/amavis restart
/etc/init.d/clamav-freshclam restart
/etc/init.d/clamav-daemon restart

现在我们必须配置 Postfix 以通过 amavisd-new 管道传入电子邮件:

postconf -e 'content_filter = amavis:[127.0.0.1]:10024'
postconf -e 'receive_override_options = no_address_mappings'

然后将以下行附加到 /etc/postfix/master.cf:

vi /etc/postfix/master.cf
[...]
amavis unix - - - - 2 smtp
        -o smtp_data_done_timeout=1200
        -o smtp_send_xforward_command=yes

127.0.0.1:10025 inet n - - - - smtpd
        -o content_filter=
        -o local_recipient_maps=
        -o relay_recipient_maps=
        -o smtpd_restriction_classes=
        -o smtpd_client_restrictions=
        -o smtpd_helo_restrictions=
        -o smtpd_sender_restrictions=
        -o smtpd_recipient_restrictions=permit_mynetworks,reject
        -o mynetworks=127.0.0.0/8
        -o strict_rfc821_envelopes=yes
        -o receive_override_options=no_unknown_recipient_checks,no_header_body_checks

然后重启 Postfix:

/etc/init.d/postfix restart

现在运行

netstat -tap

你应该看到 Postfix (master) 在端口 25 (smtp) 和 10025 上监听,而 amavisd-new 在端口 10024 上监听:

:/etc/courier#
 

10 安装Razor、Pyzor和DCC并配置SpamAssassin

Razor、Pyzor 和 DCC 是使用协同过滤网络的垃圾邮件过滤器。要安装 Razor 和 Pyzor,请运行

apt-get install razor pyzor

DCC 在 Ubuntu 13.10 存储库中不可用,因此我们按如下方式安装它:

cd /tmp
wget http://www.dcc-servers.net/dcc/source/dcc-dccproc.tar.Z
tar xzvf dcc-dccproc.tar.Z
cd dcc-dccproc-1.3.1.154
./configure --with-uid=amavis
make
make install
chown -R amavis:amavis /var/dcc
ln -s /var/dcc/libexec/dccifd /usr/local/bin/dccifd

现在我们必须告诉 SpamAssassin 使用这三个程序。编辑 /etc/spamassassin/local.cf 并向其中添加以下行:

vi /etc/spamassassin/local.cf
[...]
#dcc
use_dcc 1
dcc_path /usr/local/bin/dccproc

#pyzor
use_pyzor 1
pyzor_path /usr/bin/pyzor

#razor
use_razor2 1
razor_config /etc/razor/razor-agent.conf

#bayes
use_bayes 1
use_bayes_rules 1
bayes_auto_learn 1

然后我们必须在 SpamAssassin 中启用 DCC 插件。打开 /etc/spamassassin/v310.pre 并取消注释 loadplugin Mail::SpamAssassin::Plugin::DCC 行:

vi /etc/spamassassin/v310.pre
[...]
# DCC - perform DCC message checks.
#
# DCC is disabled here because it is not open source.  See the DCC
# license for more details.
#
loadplugin Mail::SpamAssassin::Plugin::DCC
[...]

您可以通过执行以下命令来检查您的 SpamAssassin 配置:

spamassassin --lint

它不应该显示任何错误。

之后重新启动 amavisd-new:

/etc/init.d/amavis restart

现在我们更新我们的 SpamAssassin 规则集如下:

sa-update --no-gpg

我们创建了一个 cron 作业,以便定期更新规则集。跑步

crontab -e

打开 cron 作业编辑器。创建以下 cron 作业:

23 4 */2 * * /usr/bin/sa-update --no-gpg &> /dev/null

这将在每隔一天的 4.23h 更新规则集。

©2015-2025 艾丽卡 support@alaica.com