|
|
第1行: |
第1行: |
| == Postfix 基本设置指南 ==
| | #REDIRECT[[UbuntuHelp:PostfixBasicSetupHowto/zh]] |
| | |
| 原文出处:官方wiki
| |
| | |
| 原文作者:
| |
| | |
| 授权许可:
| |
| * [http://creativecommons.org/licenses/by-sa/2.0/ 创作共用协议Attribution-ShareAlike 2.0]
| |
| * [http://www.gnu.org/copyleft/fdl.html GNU自由文档许可证]
| |
| | |
| 翻译人员:speme
| |
| | |
| 校正人员:
| |
| | |
| 贡献人员:
| |
| | |
| 适用版本:
| |
| 文章状态:[[等待翻译]]
| |
| ----
| |
| | |
| | |
| | |
| === Introduction(简介) ===
| |
| | |
| This howto will help you to have a basic Postfix mail server setup for your corporate environment. The main intention of this howto is to teach how you can install and configure a basic Postfix mail server setup with IMAP and POP3 services. I do not intend to tell you how you can integrate advanced stuffs like virus checking and spam filtering with this guide.<br>
| |
| 这份说明的目标是告诉你如何在企业环境下为Postfix邮件服务器作基本的设置。这份说明的主要目的是教会你进行Postfix邮件服务器的基本配置以使其拥有IMAP与POP3功能。但是,你无法在这份说明中学到在Postfix邮件服务器中集成像病毒过滤及垃圾邮件过滤等高级的功能的方法。
| |
| | |
| This how to is going to be a kind of more academic howto for staters with Postfix. My advanced postfix guides are PostfixVirtualMailBoxClamSmtpHowto and PostfixCompleteVirtualMailSystemHowto. If you are a newbie to Postfix enjoy them once you have finished this basic howto.<br>
| |
| 这份说明是针对刚开始使用Postfix的用户提供一个基础的认识。其它的高级指南是[[PostfixVirtualMailBoxClamSmtpHowto|Postfix - Postfix 虚拟邮箱和病毒过滤指南]]以及[[PostfixCompleteVirtualMailSystemHowto|Postfix - Postfix 完整虚拟邮件系统指南]]。如果你是一个Postfix的新手,但希望使用那些高级功能的话,你应当事先了解本说明。
| |
| | |
| === Setup Overview(安装提示) ===
| |
| | |
| In our setup, Postfix sends & recieves mail from Internet and stores in the user mail boxes while clients in the Internet can retrieve their mails either from Courier IMAP or POP3. The user authentication is done by Courier Authdaemon. The following diagram shows this process.<br>
| |
| 本指南提供的安装方法,Postfix通过网络来发送及接收邮件并将它们存入用户邮箱中,用户可以通过Courier IMAP 或者 POP3 服务器来回复他们的邮件。用户验证是由 Courier Authdaemon 这个守护进程来完成的。下面的图片表现了这个过程。
| |
| | |
| [[Image:SetupOverview.jpg]]
| |
| | |
| === Anatomy of Postfix(Postfix的结构) ===
| |
| | |
| ==== Components(构件) ====
| |
| | |
| The Following figure shows the main Postfix system components, and the main information flows between them.<br>
| |
| 下面的图片表现了主要的Postfix系统组件,以及它们之间的关键信息流。
| |
| | |
| [[Image:PostfixComponents.gif]]
| |
| | |
| * Yellow ellipsoids are mail programs.黄色椭圆是邮件程序。
| |
| * Yellow boxes are mail queues or files.黄色方框是邮件队列或文件。
| |
| * Blue boxes are lookup tables.蓝色方框是查找表。
| |
| * Programs in the large box run under control by the Postfix resident master daemon.在大方框中运行的程序是由Postfix主驻留守护进程控制的。
| |
| * Data in the large box is property of the Postfix mail system. 大方框中的数字是Postfix邮件系统的属性。
| |
| | |
| ==== Receiving Mail(接收邮件) ====
| |
| | |
| When a message enters the Postfix mail system, the first stop on the inside is the incoming queue. The figure below shows the main components that are involved with new mail.<br>
| |
| 当Postfix邮件服务器收到一封新消息的时候,它将首先被放入接收队列中。下面的图表展示了新邮件处理的主要组件。<br>
| |
| | |
| [[Image:PosfixRecieving.gif]]
| |
| | |
| * Mail is posted locally. The Postfix [http://www.postfix.org/sendmail.1.html sendmail] program invokes the privileged [http://www.postfix.org/postdrop.1.html postdrop] program which deposits the message into the '''maildrop''' directory, where the message is picked up by the [http://www.postfix.org/sendmail.1.html sendmail] daemon. This daemon does some sanity checks, in order to protect the rest of the Postfix system.
| |
| * 邮件是在本地发送的。Postfix[http://www.postfix.org/sendmail.1.html 邮件发送]程序将首先调用[http://www.postfix.org/postdrop.1.html 邮件丢弃]程序将邮件丢弃到“回收站”目录下,在那里,邮件又将被 [http://www.postfix.org/sendmail.1.html 邮件发送] 进程所处理。这个进程执行一些完整性检查,以保护Postfix邮件服务器的工作。
| |
| | |
| * Mail comes in via the network. The Postfix [http://www.postfix.org/smtpd.8.html SMTP server] receives the message and does some sanity checks, in order to protect the rest of the Postfix system.
| |
| * 邮件是来自网络的。Postfix[http://www.postfix.org/smtpd.8.html SMTP 服务器]将接收这些邮件并进行完整性检查,以保护Postfix邮件服务器的工作。
| |
| | |
| * Mail is generated internally by the Postfix system itself, in order to return undeliverable mail to the sender. The [http://www.postfix.org/bounce.8.html bounce or defer] daemon brings the bad news.
| |
| * 邮件是由Postfix系统自己生成来返回无法传送的返回邮件给发送者。[http://www.postfix.org/bounce.8.html bounce or defer]进程处理该消息。
| |
| | |
| * Mail is forwarded by the [http://www.postfix.org/local.8.html local] delivery agent, either via an entry in the system-wide [http://www.postfix.org/aliases.5.html alias] database, or via an entry in a per-user [http://www.postfix.org/aliases.5.html .forward] file. This is indicated with the unlabeled arrow.
| |
| | |
| * Mail is generated internally by the Postfix system itself, in order to [http://www.postfix.org/basic.html#notify notify] the postmaster of a problem (this path is also indicated with the unlabeled arrow).The Postfix system can be configured to notify the postmaster of SMTP protocol problems, [http://en.wikipedia.org/wiki/E-mail_spam UCE] policy violations, and so on.
| |
| | |
| * The [http://www.postfix.org/cleanup.8.html cleanup] daemon implements the final processing stage for new mail. It adds missing '''From:''' and other message headers, arranges for address rewriting to the standard [email protected] form, and optionally extracts recipient addresses from message headers. The '''cleanup''' daemon inserts the result as a single queue file into the '''incoming''' queue, and notifies the [http://www.postfix.org/qmgr.8.html queue manager] of the arrival of new mail. The '''cleanup''' daemon can be configured to transform addresses on the basis of [http://www.postfix.org/rewrite.html# canonical canonical] and [ http://www.postfix.org/rewrite.html#virtual virtua] table lookups. | |
| | |
| * On request by the cleanup daemon, the [ http://www.postfix.org/trivial-rewrite.8.html trivial-rewrite] daemon rewrites addresses to the standard [email protected] form. | |
| | |
| | |
| === Install Postfix 安装 Postfix<br> ===
| |
| | |
| In this setup I assume that your domain is <code><nowiki>yourdomain.com</nowiki></code> and it has a valid MX record call <code><nowiki>mail.yourdomain.com</nowiki></code>. Remember to replace <code><nowiki>yourdomain.com</nowiki></code> with your actual domain in the example codes in this howto. Also I assume that you know what an MX record is. To find out MX your type in a terminal:
| |
| | |
| 在此安装中我设想你的域名是 yourdomain.com 同时它有一个叫 mail.yourdomain.com的有效MX 记录。 记住在这个指导中要用你实际的域名替换示例代码中的 yourdomain.com。而且我认为你知道什么是MX记录。 找出MX记录你可在终端键入:
| |
| <pre>dig mx yourdomain.com
| |
| </pre>
| |
| '''To install postfix 安装 postfix'''
| |
| <pre>sudo apt-get install postfix
| |
| </pre>
| |
| Intall mailx package for use as command mail utility program. Mail command is installed with this package.
| |
| | |
| 安装mailx包以便使用command mail实用程序。Mail command 是通过此包安装的。<br>
| |
| <pre>sudo apt-get install mailx
| |
| </pre>
| |
| | |
| === Test your default setup ===
| |
| | |
| Add a user before you start this.
| |
| | |
| <pre><nowiki>
| |
| sudo useradd -m -s /bin/bash fmaster
| |
| sudo passwd fmaster
| |
| </nowiki></pre>
| |
| | |
| Test your default installation using the following code segment.
| |
| | |
| <pre><nowiki>
| |
| telnet localhost 25
| |
| </nowiki></pre>
| |
| | |
| Postfix will prompt like following in the terminal so that you can use to type SMTP commands.
| |
| | |
| <pre><nowiki>
| |
| Trying 127.0.0.1...
| |
| Connected to mail.fossedu.org.
| |
| Escape character is '^]'.
| |
| 220 localhost.localdomain ESMTP Postfix (Ubuntu)
| |
| </nowiki></pre>
| |
| | |
| Type the following code segment in Postfix's prompt.
| |
| | |
| <pre><nowiki>
| |
| ehlo localhost
| |
| mail from: root@localhost
| |
| rcpt to: fmaster@localhost
| |
| data
| |
| Subjet: My first mail on Postfix
| |
| Hi,
| |
| Are you there?
| |
| regards,
| |
| Admin
| |
| . (Type the .[dot] in a new Line and press Enter )
| |
| quit
| |
| </nowiki></pre>
| |
| | |
| Check the mailbox of <code><nowiki>fmaster</nowiki></code>
| |
| | |
| <pre><nowiki>
| |
| su - fmaster
| |
| mail
| |
| </nowiki></pre>
| |
| | |
| When your type <code><nowiki>mail</nowiki></code> command an output like follows display in your terminal.
| |
| | |
| <pre><nowiki>
| |
| Mail version 8.1.2 01/15/2001. Type ? for help.
| |
| "/var/mail/fmaster": 2 messages 2 new
| |
| >N 1 root@localhost Mon Mar 6 12:49 13/479 Just a test
| |
| N 2 root@localhost Mon Mar 6 12:51 15/487 My first mail
| |
| &
| |
| </nowiki></pre>
| |
| You will observe that mails are indexed by numbers and you can type the number of which the mail that you want to read. For example type no <code><nowiki>"2"</nowiki></code> to read the 2nd mail. The type <code><nowiki>"q"</nowiki></code> to quit. The mail will be written to a file called <code><nowiki>mbox</nowiki></code> in user's home directory. According to our example it will be <code><nowiki>/home/fmaster/mbox</nowiki></code>.
| |
| | |
| All messages in an mbox type of mailbox are concatenated and stored in a single file. The beginning of each message is indicated by a line whose first five characters are "From " and a blank line is appended to the end of each message
| |
| | |
| === Setting Postfix Support for Maildir-style Mailboxes ===
| |
| | |
| Maildir is a format for an e-mail spool that does not require file locking to maintain message integrity because the messages are kept in separate files with unique names. A Maildir is a directory (often named Maildir) with three subdirectories named tmp, new, and cur. The subdirectories should all reside on the same filesystem.
| |
| | |
| Another reason to use Maildir format is that Courier IMAP/POP3 servers only work with Maildir format of mailboxes.
| |
| | |
| Please find out more about Maildir [http://en.wikipedia.org/wiki/Maildir here]
| |
| | |
| | |
| <pre><nowiki>
| |
| sudo vi /etc/postfix/main.cf
| |
| </nowiki></pre>
| |
| | |
| Add the following code segment:
| |
| | |
| <pre><nowiki>
| |
| home_mailbox = Maildir/
| |
| </nowiki></pre>
| |
| | |
| Comment the Line <code><nowiki> mailbox_command = procmail -a "$EXTENSION"</nowiki></code> adding a "#" at the beginning
| |
| | |
| '''Restart Postfix''' to make changes effect.
| |
| | |
| <pre><nowiki>
| |
| sudo /etc/init.d/postfix restart
| |
| </nowiki></pre>
| |
| | |
| Test your setup again
| |
| | |
| === Installing courier IMAP and POP3 ===
| |
| | |
| <pre><nowiki>
| |
| sudo apt-get install courier-pop
| |
| sudo apt-get install courier-imap
| |
| </nowiki></pre>
| |
| | |
| = Adding local domains to postfix
| |
| | |
| <pre><nowiki>
| |
| sudo vi /etc/postfix/main.cf
| |
| </nowiki></pre>
| |
| | |
| '''Add your domain to:'''
| |
| | |
| <pre><nowiki>
| |
| sudo vi /etc/postfix/main.cf
| |
| </nowiki></pre>
| |
| | |
| Add your domain to <code><nowiki>mydestination</nowiki></code>. Once added it should be like the following code segment.
| |
| | |
| <pre><nowiki>
| |
| ...
| |
| mydestination = mail.fossedu.org, localhost.localdomain, localhost, yourdoamin.com
| |
| ...
| |
| </nowiki></pre>
| |
| | |
| '''Add your local network to:'''
| |
| | |
| <pre><nowiki>
| |
| sudo vi /etc/postfix/main.cf
| |
| </nowiki></pre>
| |
| | |
| I assume that your local network is 192.168.1.0/24 and add your local network to <code><nowiki>mynetworks</nowiki></code>. Once added it should be like the following code segment.
| |
| | |
| <pre><nowiki>
| |
| mynetworks = 127.0.0.0/8, 192.168.1.0/24
| |
| </nowiki></pre>
| |
| | |
| '''Make Postfix to receive mail from the Internet'''
| |
| | |
| Set <code><nowiki>inet_interfaces = all</nowiki></code> in <code><nowiki>/etc/postfix/main.cf</nowiki></code> using:
| |
| | |
| <pre><nowiki>
| |
| sudo vi /etc/postfix/main.cf
| |
| </nowiki></pre>
| |
| | |
| Finally Restart Postfix;
| |
| | |
| <pre><nowiki>
| |
| sudo /etc/init.d/postfix restart
| |
| </nowiki></pre>
| |
| | |
| Test your setup again using following code:
| |
| | |
| <pre><nowiki>
| |
| telnet mail.yourdomain.com 25
| |
| ehlo yourdmain.com
| |
| | |
| | |
| data
| |
| Subject: My first mail for my domain
| |
| Hi,
| |
| Are you there?
| |
| regards,
| |
| Admin
| |
| . (and Enter In a new Line)
| |
| quit
| |
| </nowiki></pre>
| |
| | |
| Check the mailbox of <code><nowiki>fmaster</nowiki></code>
| |
| | |
| <pre><nowiki>
| |
| su - fmaster
| |
| cd Maildir/new
| |
| ls
| |
| </nowiki></pre>
| |
| | |
| Now you will see mail has a separate file
| |
| | |
| == Testing Courier POP3 ==
| |
| | |
| Type in a terminal:
| |
| | |
| <pre><nowiki>
| |
| telnet mail.yourdomain.com 110
| |
| </nowiki></pre>
| |
| | |
| Use the following example code segment for your test. Be intelligent to tweak the changes appropriately to your environment. An output like follows will display in your terminal.
| |
| | |
| <pre><nowiki>
| |
| Connected to mail.yourdomain.com (69.60.109.217).
| |
| Escape character is '^]'.
| |
| +OK Hello there.
| |
| </nowiki></pre>
| |
| | |
| Type the following code segment in the prompt provided by the Courier POP3 server. I assume that you inetligent enough not to type the lines which starts from <code><nowiki>+OK</nowiki></code>
| |
| | |
| <pre><nowiki>
| |
| user fmaster
| |
| +OK Password required.
| |
| pass password
| |
| +OK logged in.
| |
| quit
| |
| </nowiki></pre>
| |
| | |
| === Testing Courier IMAP ===
| |
| | |
| Type in a terminal:
| |
| | |
| <pre><nowiki>
| |
| telnet mail.yourdomain.com 143
| |
| </nowiki></pre>
| |
| | |
| Use the following example code segment for your test. Be intelligent to tweak the changes appropriately to your environment. An output like follows will display in your terminal.
| |
| | |
| <pre><nowiki>
| |
| * OK [CAPABILITY IMAP4rev1 UIDPLUS CHILDREN NAMESPACE THREAD=ORDEREDSUBJECT THREAD=REFERENCES SORT QUOTA IDLE ACL ACL2=UNION STARTTLS XCOURIEROUTBOX=INBOX.Outbox] Courier-IMAP ready. Copyright 1998-2005 Double Precision, Inc. See COPYING for distribution information.
| |
| </nowiki></pre>
| |
| | |
| Type the following code segment in the prompt provided by the Courier IMAP server.
| |
| | |
| <pre><nowiki>
| |
| a login fmaster password
| |
| a OK LOGIN Ok.
| |
| a logout
| |
| </nowiki></pre>
| |
| | |
| === Local Alias database ===
| |
| | |
| When mail is to be delivered locally, the local delivery agent runs each local recipient name through the aliases database. The mapping does not affect addresses in message headers. Local aliases are typically used to implement distribution lists, or to direct mail for standard aliases such as '''postmaster''' to real people. The table can also be used to map Firstname.Lastname addresses to login names.
| |
| | |
| Alias lookups are enabled by default and you will see following code segment in '''main.cf''' file.
| |
| | |
| <pre><nowiki>
| |
| ...
| |
| alias_maps = hash:/etc/aliases
| |
| ...
| |
| </nowiki></pre>
| |
| | |
| ==== Creating an alias for an account ====
| |
| | |
| The following codes illustrate how you can setup an alias. This step is optional since we are going to configure virtual mail domains later in this howto. I have added this step to make understand how you can do this in case of a requirement.
| |
| | |
| '''Create a user'''
| |
| | |
| <pre><nowiki>
| |
| sudo useradd -m -s /bin/bash sysadmin
| |
| sudo passwd sysadmin
| |
| </nowiki></pre>
| |
| | |
| '''Edit the alias table'''
| |
| | |
| Open the alias file with:
| |
| | |
| <pre><nowiki>
| |
| sudo vi /etc/aliases
| |
| </nowiki></pre>
| |
| | |
| Add the following code:
| |
| | |
| <pre><nowiki>
| |
| fmaster: sysadmin
| |
| </nowiki></pre>
| |
| | |
| To make your changes effect type:
| |
| | |
| <pre><nowiki>
| |
| sudo newaliases
| |
| </nowiki></pre>
| |
| | |
| To test your changes send a mail to <code><nowiki>fmaster</nowiki></code> and check the mail in <code><nowiki>/home/sysadmin/Maildir/new</nowiki></code> folder.
| |
| | |
| | |
| === Per User .forward Files ===
| |
| | |
| Users can control their own mail delivery by specifying destinations in a file called .forward in their home directories. The syntax of these files is the same as with system aliases, except that the lookup key and colon are not present.
| |
| | |
| I will illustrate an example here:
| |
| | |
| Assume that you need to for all the mails which comes sysadmin account to an another account do like this
| |
| | |
| <pre><nowiki>
| |
| su - sysadmin
| |
| touch .forward
| |
| </nowiki></pre>
| |
| | |
| Then open the .forward file
| |
| | |
| <pre><nowiki>
| |
| vi .forward
| |
| </nowiki></pre>
| |
| | |
| Add the following code:
| |
| | |
| <pre><nowiki>
| |
| | |
| </nowiki></pre>
| |
| | |
| Remember to use email address which exists in this exercise.
| |
| | |
| Now send a mail to <code><nowiki>sysadmin</nowiki></code> and mail should come to [email protected] | |
| | |
| === Postfix virtual Aliases for separate domains and Linux system accounts ===
| |
| | |
| With this approach, every hosted domain can have its own info etc. email address. However, it still uses LINUX system accounts for local mailbox deliveries.
| |
| | |
| With virtual alias domains, each hosted address is aliased to a local UNIX system account or to a remote address. The example below shows how to use this mechanism for the fossedu.org and linuxelabs.com domains.
| |
| | |
| Open the '''main.cf''' file:
| |
| | |
| <pre><nowiki>
| |
| sudo vi /etc/postfix/main.cf
| |
| </nowiki></pre>
| |
| | |
| Add the following code segment:
| |
| | |
| <pre><nowiki>
| |
| virtual_alias_domains = fossedu.org linuxelabs.com
| |
| virtual_alias_maps = hash:/etc/postfix/virtual
| |
| </nowiki></pre>
| |
| | |
| Edit the <code><nowiki>/etc/postfix/virtual</nowiki></code> file:
| |
| | |
| | |
| Add two Linux system accounts
| |
| | |
| <pre><nowiki>
| |
| sudo useradd -m -s /bin/bash sigiri
| |
| sudo useradd -m -s /bin/bash kala
| |
| </nowiki></pre>
| |
| | |
| Set Password for the above users.
| |
| | |
| <pre><nowiki>
| |
| sudo passwd sigiri
| |
| sudo passwd kala
| |
| </nowiki></pre>
| |
| | |
| | |
| <pre><nowiki>
| |
| sudo vi /etc/postfix/virtual
| |
| </nowiki></pre>
| |
| | |
| Add the following code segment:
| |
| | |
| <pre><nowiki>
| |
| | |
| | |
| </nowiki></pre>
| |
| | |
| To create a Map Database type :
| |
| <pre><nowiki>
| |
| sudo postmap /etc/postfix/virtual
| |
| </nowiki></pre>
| |
| The postmap is utility program that will convert <code><nowiki>/etc/postfix/virtual</nowiki></code> to <code><nowiki>/etc/postfix/virtual.db</nowiki></code> Berkley DB format, so that Postfix can access the data faster.
| |
| | |
| Restart Postfix to make changes effect:
| |
| | |
| <pre><nowiki>
| |
| sudo /etc/init.d/postfix restart
| |
| </nowiki></pre>
| |
| | |
| | |