溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊(cè)×
其他方式登錄
點(diǎn)擊 登錄注冊(cè) 即表示同意《億速云用戶服務(wù)條款》

怎么在Ubuntu環(huán)境下搭建郵件服務(wù)器

發(fā)布時(shí)間:2021-09-18 09:29:47 來(lái)源:億速云 閱讀:1210 作者:chen 欄目:系統(tǒng)運(yùn)維

這篇文章主要講解了“怎么在Ubuntu環(huán)境下搭建郵件服務(wù)器”,文中的講解內(nèi)容簡(jiǎn)單清晰,易于學(xué)習(xí)與理解,下面請(qǐng)大家跟著小編的思路慢慢深入,一起來(lái)研究和學(xué)習(xí)“怎么在Ubuntu環(huán)境下搭建郵件服務(wù)器”吧!

安裝 Dovecot

啟動(dòng)你的 Ubuntu 系統(tǒng)并安裝 Dovecot:

$ sudo apt-get install dovecot-imapd dovecot-pop3d

它會(huì)安裝可用的配置,并在完成后自動(dòng)啟動(dòng),你可以用 ps ax | grep dovecot 確認(rèn):

$ ps ax | grep dovecot 15988 ?  Ss 0:00 /usr/sbin/dovecot 15990 ?  S  0:00 dovecot/anvil 15991 ?  S  0:00 dovecot/log

打開(kāi)你的 Postfix 配置文件 /etc/postfix/main.cf,確保配置了maildir 而不是 mbox 的郵件存儲(chǔ)方式,mbox  是給每個(gè)用戶一個(gè)單一大文件,而 maildir 是每條消息都存儲(chǔ)為一個(gè)文件。大量的小文件比一個(gè)龐大的文件更穩(wěn)定且易于管理。添加如下兩行,第二行告訴  Postfix 你需要 maildir 格式,并且在每個(gè)用戶的家目錄下創(chuàng)建一個(gè) .Mail 目錄。你可以取任何名字,不一定要是 .Mail:

mail_spool_directory = /var/mail home_mailbox = .Mail/

現(xiàn)在調(diào)整你的 Dovecot 配置。首先把原始的 dovecot.conf 文件重命名放到一邊,因?yàn)樗鼤?huì)調(diào)用存放在 conf.d  中的文件,在你剛剛開(kāi)始學(xué)習(xí)時(shí)把配置放一起更簡(jiǎn)單些:

$ sudo mv /etc/dovecot/dovecot.conf /etc/dovecot/dovecot-oldconf

現(xiàn)在創(chuàng)建一個(gè)新的 /etc/dovecot/dovecot.conf:

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 }

注意 mail_location = maildir 必須和 main.cf 中的 home_mailbox 參數(shù)匹配。保存你的更改并重新加載  Postfix 和 Dovecot 配置:

$ sudo postfix reload $ sudo dovecot reload

快速導(dǎo)出配置

使用下面的命令來(lái)快速查看你的 Postfix 和 Dovecot 配置:

$ postconf -n $ doveconf -n

測(cè)試 Dovecot

現(xiàn)在再次啟動(dòng) telnet,并且給自己發(fā)送一條測(cè)試消息。粗體顯示的是你輸入的命令。studio 是我服務(wù)器的主機(jī)名,因此你必須用自己的:

$ 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.

現(xiàn)在請(qǐng)求 Dovecot 來(lái)取回你的新消息,使用你的 Linux 用戶名和密碼登錄:

$ 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.

花一點(diǎn)時(shí)間比較***個(gè)例子中輸入的消息和第二個(gè)例子中接收的消息。 返回地址和日期是很容易偽造的,但 Postfix  不會(huì)被愚弄。大多數(shù)郵件客戶端默認(rèn)顯示一個(gè)最小的標(biāo)頭集,但是你需要讀取完整的標(biāo)頭才能查看真實(shí)的回溯。

你也可以在你的 ~/Mail/cur 目錄中查看你的郵件,它們是普通文本,我已經(jīng)有兩封測(cè)試郵件:

$ ls .Mail/cur/ 1480540325.V806I28e0229M351743.studio:2,S 1480555224.V806I28e000eM41463.studio:2,S

測(cè)試 IMAP

我們 Dovecot 同時(shí)啟用了 POP3 和 IMAP 服務(wù),因此讓我們使用 telnet 測(cè)試 IMAP。

$ 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

Thunderbird 郵件客戶端

圖 1 中的屏幕截圖顯示了我局域網(wǎng)上另一臺(tái)主機(jī)上的圖形郵件客戶端中的郵件。

怎么在Ubuntu環(huán)境下搭建郵件服務(wù)器

圖 1: Thunderbird mail

此時(shí),你已有一個(gè)可以工作的 IMAP 和 POP3  郵件服務(wù)器,并且你也知道該如何測(cè)試你的服務(wù)器。你的用戶可以在他們?cè)O(shè)置郵件客戶端時(shí)選擇要使用的協(xié)議。如果您只想支持一個(gè)郵件協(xié)議,那么只需要在您的 Dovecot  配置中留下你要的協(xié)議名字。

感謝各位的閱讀,以上就是“怎么在Ubuntu環(huán)境下搭建郵件服務(wù)器”的內(nèi)容了,經(jīng)過(guò)本文的學(xué)習(xí)后,相信大家對(duì)怎么在Ubuntu環(huán)境下搭建郵件服務(wù)器這一問(wèn)題有了更深刻的體會(huì),具體使用情況還需要大家實(shí)踐驗(yàn)證。這里是億速云,小編將為大家推送更多相關(guān)知識(shí)點(diǎn)的文章,歡迎關(guān)注!

向AI問(wèn)一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI