个人工具

“UbuntuHelp:PostfixCompleteVirtualMailSystemHowto/zh”的版本间的差异

来自Ubuntu中文

跳转至: 导航, 搜索
摘要
整体架构图
第93行: 第93行:
 
* '''Courier''' :像postfix一样的独立的邮件服务,我们利用它的pop3/IMAP服务部件使用户访问邮箱。
 
* '''Courier''' :像postfix一样的独立的邮件服务,我们利用它的pop3/IMAP服务部件使用户访问邮箱。
 
* '''SASL''':简单认证与安全层 。你的邮件服务仅信任内部地址,所以对使用外部网络地址的用户进行身份认证。通过SASL对SMTP认证使你的邮件服务信任他们。
 
* '''SASL''':简单认证与安全层 。你的邮件服务仅信任内部地址,所以对使用外部网络地址的用户进行身份认证。通过SASL对SMTP认证使你的邮件服务信任他们。
 +
== How Postfix Mappings Work? ==
 +
It is very important to understand how Postfix mapping works. Heart of our system is Postfix mapping. Let's discuss it here. Don't skip this section.
 +
The generic literal meaning of mapping is assign one value to another. What we have to map in Postfix is email user accounts or email address. One example is '''<code><nowiki>/etc/aliases</nowiki></code>''', the  local aliases or local system users mapping file used by Postfix. The syntax of this file is:
 +
<pre><nowiki>
 +
postmaster: root
 +
</nowiki></pre>
 +
This makes all the mails which are coming to '''<code><nowiki>postmaster@yourdomain.tld</nowiki></code>''' are redirected to '''<code><nowiki>root@yourdomain.tld</nowiki></code>'''. We can divide the above syntax to Left Hand Side '''LHS''' and Right Hand Side '''RHS'''. This RHS and LHS are common abbreviations which we usually used in mappings. The following table will make this idea even more clear.
 +
{|border="1" cellspacing="0"
 +
|'''LHS'''||'''RHS'''
 +
|-
 +
|postmaster:||root
 +
|}
 +
{|border="1" cellspacing="0"
 +
| https://help.ubuntu.com/community/PostfixCompleteVirtualMailSystemHowto?action=AttachFile&do=get&target=IconHint.png || Usually we do not use colon(:) in LHS for Postfix and this has been done for backward compatibility with historical reasons. The local alias file is a special file that is compiled with '''newaliases''' command but not with usual Postfix mapping command '''postmap'''
 +
|}
 +
With a basic default Postfix installation we use text file for mappings. We write the mappings into this file and then convert it into a '''hash''' file using '''postmap''' command so Postfix can look up items quickly. For example, assume that we need to map our virtual mailboxes in a file called '''<code><nowiki>/etc/Postfix/virtual_mailboxes</nowiki></code>'''. The syntax of this file look like:
 +
<pre><nowiki>
 +
info@domain1.com sigiri
 +
info@domain2.com kala
 +
</nowiki></pre>
 +
You may have noticed that we don't have colon(:) in the '''LHS''' of the mappings file
 +
Then you need to run:
 +
<pre><nowiki>
 +
postmap /etc/postfix/virtual_mailboxes
 +
</nowiki></pre>
 +
You can access this mappings in the Postfix configuration file by including the following line:
 +
<pre><nowiki>
 +
virtual_mailbox_maps = hash:/etc/postfix/virtual_mailboxes
 +
</nowiki></pre>
 +
In our setup, we will replace this text mapping files with MySQL tables. Our intention is to make data handling lot more flexible, robust, and scalable. Since database tables can and usually contain more than just two columns you will need to tell Postfix which database column is meant to be the LHS and which is the RHS. This is accomplished by creating a configuration file which will look something like this:
 +
<pre><nowiki>
 +
user = postfix
 +
password = YJiNLQtubgnOE
 +
hosts = 127.0.0.1
 +
dbname = postfix
 +
table = mailbox
 +
select_field = maildir
 +
where_field = username
 +
#additional_conditions = and active = '1'
 +
</nowiki></pre>
 +
For the purposes of this discussion, lets assume this is saved in a file called '''<code><nowiki>/etc/postfix/mysql_virtual_mailbox_maps.cf</nowiki></code>'''. You would then be able to use this mapping in postfix using the following entry in '''<code><nowiki>main.cf</nowiki></code>''' file.
 +
<pre><nowiki>virtual_mailbox_maps = mysql:/etc/postfix/mysql_virtual_mailbox_maps.cf
 +
</nowiki></pre>
 +
The fields in this configuration file are the '''user''' that needs to connect to the MySQL database, '''password''' of that MySQL user, '''dbname''', the name of the MySQL database, '''table''' ,the name of the table in MySQL database and '''hosts''', the name of the server that MySQL runs on.
 +
Postfix uses the this configuration file as a guide on how to use the database table as a mapping similar to the mapping file with two fields described above. The LHS of the mapping is defined as '''<code><nowiki>where_field</nowiki></code>''' and the RHS is defined as '''<code><nowiki>select_field</nowiki></code>'''. In this example we will map the '''<code><nowiki>maildir</nowiki></code>''' column to the '''<code><nowiki>username</nowiki></code>''' column. Using the configuation, Postfix constructs a SQL query something like ''select maildir from postfix.mailbox where username='johndoe' '' to lookup the maildir for a given username. The following table breaks this distiction out:
 +
{|border="1" cellspacing="0"
 +
|'''LHS'''||'''RHS'''
 +
|-
 +
|where_field||select_field
 +
|-
 +
|username||maildir
 +
|}

2008年7月5日 (六) 08:20的版本

摘要

在网上有许多HOWTO来描述如何创建邮件服务器,不同的人对MTAs有不同选择.有的人喜欢用Qmail有些人喜欢用Postfix和Exim.很长一段时间内我都喜欢用Qmail来做为我的MTA,它是一个极好的软件.但是Qmail是需要许可证的,没有方便用户在他们所习惯使用的平台上简单使用的编译好的可执行代码。虽然安装Qmail并不是那么困难,但是用户需要应用各种各样的补丁和技巧等完成完全安装。由于上述原因,并且它一旦安装完毕,运行情况还是令人满意的。所以Qmail成为了很多电脑怪杰的最爱。Qmail的缺点是升级困难,因为每次都需要编译源码并安装。综上所述,决定使用Postfix:一种像Qmail一样快速和安全的MTA,并且易与在任何Linux版本上安装和配置Basic System . Postfix 有许多附加功能并且支持Maildir 邮箱格式, PostgreSQL 后台MySQL很容易存储和管理虚拟域。这里将为希望使用Ubuntu Linux作为服务平台的ISPs,虚拟主机提供商,单个公司等安装一个完整的包含发病毒和垃圾邮件虚拟邮件域系统。

系统概述

开始安装之前,必须了解我们的系统是如何工作的。一个虚拟邮件系统必须能够控制许多域,这些域有很多用户并且用户使用不同接口。当你在同一个邮件系统中控制多个域的时候,虚拟邮件系统会提出一些管理问题。我们必须用我们的技术回答这些问题。例如,你有下面的问题需要回答。

  • 如果有两个用户在不同的域中使用了同一个用户名,你怎么办?
  • 如果你提供了IMAP访问和smtp认证,如何将不同的认证值守程序组合在同一个系统中呢?
  • 如何保证构成系统的各个组件的安全性?
  • 如果用户要求使用自己的垃圾邮件过滤策略,我们应该如何处理?
  • 每一个域的管理员要求使用基于web接口来管理他们的邮件域。
  • 如何为postfix建立一个基于web的管理系统。
  • 每个用户要求基于web接口改变邮件帐户密码。
  • 如何备份用户帐号数据库及灾难恢复。
  • 利用ssl实现传输层安全。
  • 控制任何一个域的邮件列表。

你如何一并处理以上提出的所有问题?不要担心,我会逐个回答这些问题。高高兴兴地继续读下去。

使用这个系统你会得到什么

  • 基于web的系统管理
  • 域的数量没有限制
  • 与操作系统用户无关的虚拟邮件用户
  • 特定域用户名
  • 邮箱容量分配
  • 通过web访问邮件帐号
  • 基于web接口改变用户密码
  • 支持IMAP,POP3
  • 自动回复
  • SMTP认证保证安全中转
  • SSL保证传输层安全
  • 强力垃圾邮件过滤
  • 反病毒过滤
  • 日志分析

必备软件包

我们系统必须使用下列程序包,大多数可以在APT中找到。在安装小节部分,你会学会如何安装和配置他们。

整体架构图

下面图示了我们建立的整体架构,如果你仔细观察这张图,你能从图上了解整个系统。

PostfixCompleteVirtualMailSystemHowto?action=AttachFile&do=get&target=CompleteSetupOverview.png

在我们的系统中:

  • Postfix:负责通过MTA接收和发送emails。
  • MySQL :数据库服务器保存postfix的控制信息。主要涉及用户信息,域信息,email转发及密码
  • Courier :像postfix一样的独立的邮件服务,我们利用它的pop3/IMAP服务部件使用户访问邮箱。
  • SASL:简单认证与安全层 。你的邮件服务仅信任内部地址,所以对使用外部网络地址的用户进行身份认证。通过SASL对SMTP认证使你的邮件服务信任他们。

How Postfix Mappings Work?

It is very important to understand how Postfix mapping works. Heart of our system is Postfix mapping. Let's discuss it here. Don't skip this section. The generic literal meaning of mapping is assign one value to another. What we have to map in Postfix is email user accounts or email address. One example is /etc/aliases, the local aliases or local system users mapping file used by Postfix. The syntax of this file is:

postmaster: root

This makes all the mails which are coming to postmaster@yourdomain.tld are redirected to root@yourdomain.tld. We can divide the above syntax to Left Hand Side LHS and Right Hand Side RHS. This RHS and LHS are common abbreviations which we usually used in mappings. The following table will make this idea even more clear.

LHS RHS
postmaster: root
PostfixCompleteVirtualMailSystemHowto?action=AttachFile&do=get&target=IconHint.png Usually we do not use colon(:) in LHS for Postfix and this has been done for backward compatibility with historical reasons. The local alias file is a special file that is compiled with newaliases command but not with usual Postfix mapping command postmap

With a basic default Postfix installation we use text file for mappings. We write the mappings into this file and then convert it into a hash file using postmap command so Postfix can look up items quickly. For example, assume that we need to map our virtual mailboxes in a file called /etc/Postfix/virtual_mailboxes. The syntax of this file look like:

info@domain1.com sigiri
info@domain2.com kala

You may have noticed that we don't have colon(:) in the LHS of the mappings file Then you need to run:

postmap /etc/postfix/virtual_mailboxes

You can access this mappings in the Postfix configuration file by including the following line:

virtual_mailbox_maps = hash:/etc/postfix/virtual_mailboxes

In our setup, we will replace this text mapping files with MySQL tables. Our intention is to make data handling lot more flexible, robust, and scalable. Since database tables can and usually contain more than just two columns you will need to tell Postfix which database column is meant to be the LHS and which is the RHS. This is accomplished by creating a configuration file which will look something like this:

user = postfix
password = YJiNLQtubgnOE
hosts = 127.0.0.1
dbname = postfix
table = mailbox
select_field = maildir
where_field = username
#additional_conditions = and active = '1'

For the purposes of this discussion, lets assume this is saved in a file called /etc/postfix/mysql_virtual_mailbox_maps.cf. You would then be able to use this mapping in postfix using the following entry in main.cf file.

virtual_mailbox_maps = mysql:/etc/postfix/mysql_virtual_mailbox_maps.cf

The fields in this configuration file are the user that needs to connect to the MySQL database, password of that MySQL user, dbname, the name of the MySQL database, table ,the name of the table in MySQL database and hosts, the name of the server that MySQL runs on. Postfix uses the this configuration file as a guide on how to use the database table as a mapping similar to the mapping file with two fields described above. The LHS of the mapping is defined as where_field and the RHS is defined as select_field. In this example we will map the maildir column to the username column. Using the configuation, Postfix constructs a SQL query something like select maildir from postfix.mailbox where username='johndoe' to lookup the maildir for a given username. The following table breaks this distiction out:

LHS RHS
where_field select_field
username maildir