2016-12-29 11:57:29 +08:00
|
|
|
|
在Ubuntu上构建一台Email服务器(二)
|
2016-12-29 04:34:23 +08:00
|
|
|
|
============================================================
|
|
|
|
|
|
|
|
|
|
### [dovecot-email.jpg][4]
|
|
|
|
|
|
|
|
|
|
![Dovecot email](https://www.linux.com/sites/lcom/files/styles/rendered_file/public/dovecot-email.jpg?itok=tY4veggw "Dovecot email")
|
2016-12-29 11:57:29 +08:00
|
|
|
|
本教程的第2部分将介绍如何使用Dovecot将邮件从Postfix服务器移动到用户的收件箱。以[Creative Commons Zero][2]Pixabay方式授权发布
|
2016-12-29 04:34:23 +08:00
|
|
|
|
|
2016-12-29 11:57:29 +08:00
|
|
|
|
在[第一部分][5]中,我们安装并测试了Postfix SMTP服务器。Postfix或任何SMTP服务器都不是一个完整的邮件服务器,因为它所做的是在SMTP服务器之间移动邮件。我们需要Dovecot将邮件从Postfix服务器移动到用户的收件箱中。
|
2016-12-29 04:34:23 +08:00
|
|
|
|
|
2016-12-29 11:57:29 +08:00
|
|
|
|
Dovecot支持两种标准邮件协议:IMAP(Internet邮件访问协议)和POP3(邮局协议)。 IMAP服务器保留服务器上的所有邮件。您的用户可以选择将邮件下载到计算机或仅在服务器上访问它们。 IMAP对于有多台机器的用户是方便的。但对你而言会有更多的工作,因为你必须确保你的服务器始终可用,而且IMAP服务器需要大量的存储和内存。
|
2016-12-29 04:34:23 +08:00
|
|
|
|
|
2016-12-29 11:57:29 +08:00
|
|
|
|
POP3是较旧的协议。POP3服务器可以比IMAP服务器服务更多的用户,因为邮件会下载到用户的计算机。大多数邮件客户端可以选择在服务器上保留一定天数的邮件,因此POP3的行为有点像IMAP。但它不是IMAP,当你像IMAP那样做那么常常会下载多次或意外删除。
|
2016-12-29 04:34:23 +08:00
|
|
|
|
|
2016-12-29 11:57:29 +08:00
|
|
|
|
### 安装 Dovecot
|
2016-12-29 04:34:23 +08:00
|
|
|
|
|
2016-12-29 11:57:29 +08:00
|
|
|
|
启动你信任的Ubuntu系统并安装Dovecot:
|
2016-12-29 04:34:23 +08:00
|
|
|
|
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
$ sudo apt-get install dovecot-imapd dovecot-pop3d
|
|
|
|
|
```
|
|
|
|
|
|
2016-12-29 11:57:29 +08:00
|
|
|
|
它会在安装可用的配置并在完成后自动启动,你可以用`ps ax | grep dovecot`确认:
|
2016-12-29 04:34:23 +08:00
|
|
|
|
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
$ ps ax | grep dovecot
|
|
|
|
|
15988 ? Ss 0:00 /usr/sbin/dovecot
|
|
|
|
|
15990 ? S 0:00 dovecot/anvil
|
|
|
|
|
15991 ? S 0:00 dovecot/log
|
|
|
|
|
```
|
|
|
|
|
|
2016-12-29 11:57:29 +08:00
|
|
|
|
打开你的Postfix配置文件`/etc/postfix/main.cf`,确保配置了maildirs而不是mbox邮件存储,mbox是对于每个用户的大文件,而maildir是每条消息都有一个文件。大量的小文件比一个庞大的文件更稳定且易于管理。下面添加两行,第二行告诉Postfix你需要maildir格式,并且在每个用户的家目录下创建一个`.Mail`目录。你可以取任何名字,不一定要是`.Mail`:
|
2016-12-29 04:34:23 +08:00
|
|
|
|
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
mail_spool_directory = /var/mail
|
|
|
|
|
home_mailbox = .Mail/
|
|
|
|
|
```
|
|
|
|
|
|
2016-12-29 11:57:29 +08:00
|
|
|
|
现在调整你的Dovecot配置。首先把原始的`dovecot.conf`文件重命名,因为它会调用`conf.d`中的文件来让事情简单些:
|
2016-12-29 04:34:23 +08:00
|
|
|
|
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
$ sudo mv /etc/dovecot/dovecot.conf /etc/dovecot/dovecot-oldconf
|
|
|
|
|
```
|
|
|
|
|
|
2016-12-29 11:57:29 +08:00
|
|
|
|
现在创建一个新的`/etc/dovecot/dovecot.conf`:
|
2016-12-29 04:34:23 +08:00
|
|
|
|
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
disable_plaintext_auth = no
|
|
|
|
|
mail_location = maildir:~/.Mail
|
|
|
|
|
namespace inbox {
|
|
|
|
|
inbox = yes
|
|
|
|
|
mailbox Drafts {
|
|
|
|
|
special_use = \Drafts
|
|
|
|
|
}
|
|
|
|
|
mailbox Sent {
|
|
|
|
|
special_use = \Sent
|
|
|
|
|
}
|
|
|
|
|
mailbox Trash {
|
|
|
|
|
special_use = \Trash
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
passdb {
|
|
|
|
|
driver = pam
|
|
|
|
|
}
|
|
|
|
|
protocols = " imap pop3"
|
|
|
|
|
ssl = no
|
|
|
|
|
userdb {
|
|
|
|
|
driver = passwd
|
|
|
|
|
}
|
|
|
|
|
```
|
|
|
|
|
|
2016-12-29 11:57:29 +08:00
|
|
|
|
注意`mail_location = maildir` 必须和`main.cf`中的`home_mailbox`参数匹配。保存你的更改并重新加载Postfix和Dovecot配置:
|
2016-12-29 04:34:23 +08:00
|
|
|
|
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
$ sudo postfix reload
|
|
|
|
|
$ sudo dovecot reload
|
|
|
|
|
```
|
|
|
|
|
|
2016-12-29 11:57:29 +08:00
|
|
|
|
### 快速导出配置
|
2016-12-29 04:34:23 +08:00
|
|
|
|
|
2016-12-29 11:57:29 +08:00
|
|
|
|
使用下面的命令来查看你的Postfix和Dovecot配置:
|
2016-12-29 04:34:23 +08:00
|
|
|
|
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
$ postconf -n
|
|
|
|
|
$ doveconf -n
|
|
|
|
|
```
|
|
|
|
|
|
2016-12-29 11:57:29 +08:00
|
|
|
|
### 测试 Dovecot
|
2016-12-29 04:34:23 +08:00
|
|
|
|
|
2016-12-29 11:57:29 +08:00
|
|
|
|
现在再次启动telnet,并且给自己发送一条测试消息。粗体显示的是你输入的命令。`studio`是我服务器的主机名,因此你必须用自己的:
|
2016-12-29 04:34:23 +08:00
|
|
|
|
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
$ telnet studio 25
|
|
|
|
|
Trying 127.0.1.1...
|
|
|
|
|
Connected to studio.
|
|
|
|
|
Escape character is '^]'.
|
|
|
|
|
220 studio.router ESMTP Postfix (Ubuntu)
|
|
|
|
|
EHLO studio
|
|
|
|
|
250-studio.router
|
|
|
|
|
250-PIPELINING
|
|
|
|
|
250-SIZE 10240000
|
|
|
|
|
250-VRFY
|
|
|
|
|
250-ETRN
|
|
|
|
|
250-STARTTLS
|
|
|
|
|
250-ENHANCEDSTATUSCODES
|
|
|
|
|
250-8BITMIME
|
|
|
|
|
250-DSN
|
|
|
|
|
250 SMTPUTF8
|
|
|
|
|
mail from: tester@test.net
|
|
|
|
|
250 2.1.0 Ok
|
|
|
|
|
rcpt to: carla@studio
|
|
|
|
|
250 2.1.5 Ok
|
|
|
|
|
data
|
|
|
|
|
354 End data with .Date: November 25, 2016
|
|
|
|
|
From: tester
|
|
|
|
|
Message-ID: first-test
|
|
|
|
|
Subject: mail server test
|
|
|
|
|
Hi carla,
|
|
|
|
|
Are you reading this? Let me know if you didn't get this.
|
|
|
|
|
.
|
|
|
|
|
250 2.0.0 Ok: queued as 0C261A1F0F
|
|
|
|
|
quit
|
|
|
|
|
221 2.0.0 Bye
|
|
|
|
|
Connection closed by foreign host.
|
|
|
|
|
```
|
|
|
|
|
|
2016-12-29 11:57:29 +08:00
|
|
|
|
现在请求Dovecot来取回你的新消息,使用你的Linux用户名和密码登录:
|
2016-12-29 04:34:23 +08:00
|
|
|
|
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
$ telnet studio 110
|
|
|
|
|
Trying 127.0.0.1...
|
|
|
|
|
Connected to studio.
|
|
|
|
|
Escape character is '^]'.
|
|
|
|
|
+OK Dovecot ready.
|
|
|
|
|
user carla
|
|
|
|
|
+OK
|
|
|
|
|
pass password
|
|
|
|
|
+OK Logged in.
|
|
|
|
|
stat
|
|
|
|
|
+OK 2 809
|
|
|
|
|
list
|
|
|
|
|
+OK 2 messages:
|
|
|
|
|
1 383
|
|
|
|
|
2 426
|
|
|
|
|
.
|
|
|
|
|
retr 2
|
|
|
|
|
+OK 426 octets
|
|
|
|
|
Return-Path: <tester@test.net>
|
|
|
|
|
X-Original-To: carla@studio
|
|
|
|
|
Delivered-To: carla@studio
|
|
|
|
|
Received: from studio (localhost [127.0.0.1])
|
|
|
|
|
by studio.router (Postfix) with ESMTP id 0C261A1F0F
|
|
|
|
|
for <carla@studio>; Wed, 30 Nov 2016 17:18:57 -0800 (PST)
|
|
|
|
|
Date: November 25, 2016
|
|
|
|
|
From: tester@studio.router
|
|
|
|
|
Message-ID: first-test
|
|
|
|
|
Subject: mail server test
|
|
|
|
|
|
|
|
|
|
Hi carla,
|
|
|
|
|
Are you reading this? Let me know if you didn't get this.
|
|
|
|
|
.
|
|
|
|
|
quit
|
|
|
|
|
+OK Logging out.
|
|
|
|
|
Connection closed by foreign host.
|
|
|
|
|
```
|
|
|
|
|
|
2016-12-29 11:57:29 +08:00
|
|
|
|
花一点时间比较第一个例子中输入的消息和第二个例子中接收的消息。 它很容易欺骗返回地址和日期,但Postfix不会这样。大多数邮件客户端默认显示一个最小的标头集,但是你需要读取完整的标头以查看真实的回溯。
|
2016-12-29 04:34:23 +08:00
|
|
|
|
|
|
|
|
|
You can also read your messages by looking in your `~/Mail/cur` directory. They are plain text. Mine has two test messages:
|
|
|
|
|
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
$ ls .Mail/cur/
|
|
|
|
|
1480540325.V806I28e0229M351743.studio:2,S
|
|
|
|
|
1480555224.V806I28e000eM41463.studio:2,S
|
|
|
|
|
```
|
|
|
|
|
|
2016-12-29 11:57:29 +08:00
|
|
|
|
### 测试 IMAP
|
2016-12-29 04:34:23 +08:00
|
|
|
|
|
2016-12-29 11:57:29 +08:00
|
|
|
|
我们Dovecot同时启用了POP3和IMAP,因此我们使用telnet测试IMAP。
|
2016-12-29 04:34:23 +08:00
|
|
|
|
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
$ telnet studio imap2
|
|
|
|
|
Trying 127.0.1.1...
|
|
|
|
|
Connected to studio.
|
|
|
|
|
Escape character is '^]'.
|
|
|
|
|
* OK [CAPABILITY IMAP4rev1 LITERAL+ SASL-IR LOGIN-REFERRALS
|
|
|
|
|
ID ENABLE IDLE AUTH=PLAIN] Dovecot ready.
|
|
|
|
|
A1 LOGIN carla password
|
|
|
|
|
A1 OK [CAPABILITY IMAP4rev1 LITERAL+ SASL-IR LOGIN-REFERRALS
|
|
|
|
|
ID ENABLE IDLE SORT SORT=DISPLAY THREAD=REFERENCES THREAD=REFS
|
|
|
|
|
THREAD=ORDEREDSUBJECT MULTIAPPEND URL-PARTIAL CATENATE UNSELECT
|
|
|
|
|
CHILDREN NAMESPACE UIDPLUS LIST-EXTENDED I18NLEVEL=1 CONDSTORE
|
|
|
|
|
QRESYNC ESEARCH ESORT SEARCHRES WITHIN CONTEXT=SEARCH LIST-STATUS
|
|
|
|
|
BINARY MOVE SPECIAL-USE] Logged in
|
|
|
|
|
A2 LIST "" "*"
|
|
|
|
|
* LIST (\HasNoChildren) "." INBOX
|
|
|
|
|
A2 OK List completed (0.000 + 0.000 secs).
|
|
|
|
|
A3 EXAMINE INBOX
|
|
|
|
|
* FLAGS (\Answered \Flagged \Deleted \Seen \Draft)
|
|
|
|
|
* OK [PERMANENTFLAGS ()] Read-only mailbox.
|
|
|
|
|
* 2 EXISTS
|
|
|
|
|
* 0 RECENT
|
|
|
|
|
* OK [UIDVALIDITY 1480539462] UIDs valid
|
|
|
|
|
* OK [UIDNEXT 3] Predicted next UID
|
|
|
|
|
* OK [HIGHESTMODSEQ 1] Highest
|
|
|
|
|
A3 OK [READ-ONLY] Examine completed (0.000 + 0.000 secs).
|
|
|
|
|
A4 logout
|
|
|
|
|
* BYE Logging out
|
|
|
|
|
A4 OK Logout completed.
|
|
|
|
|
Connection closed by foreign host
|
|
|
|
|
```
|
|
|
|
|
|
2016-12-29 11:57:29 +08:00
|
|
|
|
### Thunderbird邮件客户端
|
|
|
|
|
|
|
|
|
|
图1中的屏幕截图显示了我局域网上另一台主机上的图形邮件客户端中的邮件。
|
2016-12-29 04:34:23 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
### [thunderbird-mail.png][3]
|
|
|
|
|
|
|
|
|
|
![thunderbird mail](https://www.linux.com/sites/lcom/files/styles/rendered_file/public/thunderbird-mail.png?itok=IkWK5Ti_ "thunderbird mail")
|
|
|
|
|
|
2016-12-29 11:57:29 +08:00
|
|
|
|
图1: Thunderbird mail.[Used with permission][1]
|
2016-12-29 04:34:23 +08:00
|
|
|
|
|
2016-12-29 11:57:29 +08:00
|
|
|
|
此时,你已有一个工作的IMAP和POP3邮件服务器,并且你也知道该如何测试你的服务器。你的用户将在他们设置邮件客户端时选择要使用的协议。如果您只想支持一个邮件协议,那么只需要命名您的Dovecot配置中的一个。
|
2016-12-29 04:34:23 +08:00
|
|
|
|
|
2016-12-29 11:57:29 +08:00
|
|
|
|
然而,这还远远没有完成。这是一个非常简单、没有加密的开放的安装。它也只适用于与邮件服务器在同一系统上的用户。这是不可扩展的,并具有一些安全风险,例如没有密码保护。 我们会在[下周][6]了解如何创建与系统用户分开的邮件用户,以及如何添加加密。
|
2016-12-29 04:34:23 +08:00
|
|
|
|
|
|
|
|
|
--------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
via: https://www.linux.com/learn/sysadmin/building-email-server-ubuntu-linux-part-2
|
|
|
|
|
|
|
|
|
|
作者:[ CARLA SCHRODER][a]
|
2016-12-29 11:57:29 +08:00
|
|
|
|
译者:[geekpi](https://github.com/geekpi)
|
2016-12-29 04:34:23 +08:00
|
|
|
|
校对:[校对者ID](https://github.com/校对者ID)
|
|
|
|
|
|
|
|
|
|
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
|
|
|
|
|
|
|
|
|
|
[a]:https://www.linux.com/users/cschroder
|
|
|
|
|
[1]:https://www.linux.com/licenses/category/used-permission
|
|
|
|
|
[2]:https://www.linux.com/licenses/category/creative-commons-zero
|
|
|
|
|
[3]:https://www.linux.com/files/images/thunderbird-mailpng
|
|
|
|
|
[4]:https://www.linux.com/files/images/dovecot-emailjpg
|
|
|
|
|
[5]:https://www.linux.com/learn/how-build-email-server-ubuntu-linux
|
|
|
|
|
[6]:https://www.linux.com/learn/sysadmin/building-email-server-ubuntu-linux-part-3
|