Centos

在 maildir 中找不到 postfix/mailx 電子郵件,為什麼不呢?

  • October 14, 2015

CentOS 7開發機器中,我配置了 postfix 以允許在localhost地址之間交換電子郵件。 Mailx也安裝了。我能夠發送電子郵件,並且日誌文件表明郵件已送達。但是,我無法在終端中找到要查看的電子郵件。 我究竟做錯了什麼?如何在終端中查看這些新發送的郵件?

我可以通過mailx root@localhost在終端中輸入來發送電子郵件,然後按照提示添加主題和正文,然後Ctrl-D獲取命令提示符。此外,當我鍵入mailmailx以 root 身份登錄時,終端會回復一個列表,其中列出了之前儲存的一些舊電子郵件,這些舊電子郵件postfix已更改為將電子郵件儲存在 中/Maildir,但沒有找到新電子郵件。我可以在輸入時查看那些舊電子郵件nano /var/spool/mail/root,但當然新電子郵件不會儲存在/var/spool/mail/root.

沒有/var/log/mail。但是,nano /var/log/maillog包含:

Jan  5 12:09:40 localhost postfix/postfix-script[6162]: starting the Postfix mail system
Jan  5 12:09:40 localhost postfix/master[6164]: daemon started -- version 2.10.1, configuration /etc/postfix
Jan  5 12:46:00 localhost postfix/postfix-script[3036]: starting the Postfix mail system
Jan  5 12:46:00 localhost postfix/master[3047]: daemon started -- version 2.10.1, configuration /etc/postfix
Jan  5 13:12:02 localhost postfix/smtpd[4642]: connect from localhost.localdomain[127.0.0.1]
Jan  5 13:12:02 localhost postfix/smtpd[4642]: DB1249A618: client=localhost.localdomain[127.0.0.1]
Jan  5 13:12:02 localhost postfix/cleanup[4645]: DB1249A618: message-id=<1738078707.0.1420492322780.JavaMail.username@localhost.localdomain>
Jan  5 13:12:02 localhost postfix/qmgr[3058]: DB1249A618: from=<username@localhost.localdomain>, size=632, nrcpt=1 (queue active)
Jan  5 13:12:02 localhost postfix/smtpd[4642]: disconnect from localhost.localdomain[127.0.0.1]
Jan  5 13:12:02 localhost postfix/local[4646]: DB1249A618: to=<root@localhost.localdomain>, orig_to=<root@localhost>, relay=local, delay=0.11, delays=0.06/0.02/0/0.03, dsn=2.0.0, status=sent (delivered to maildir)
Jan  5 13:12:02 localhost postfix/qmgr[3058]: DB1249A618: removed
Jan  5 14:29:20 localhost postfix/pickup[5207]: 7F4439A616: uid=1000 from=<username>
Jan  5 14:29:20 localhost postfix/cleanup[5266]: 7F4439A616: message-id=<20150105222920.7F4439A616@localhost.localdomain>
Jan  5 14:29:20 localhost postfix/qmgr[3058]: 7F4439A616: from=<username@localhost.localdomain>, size=334, nrcpt=1 (queue active)
Jan  5 14:29:20 localhost postfix/local[5271]: 7F4439A616: to=<root@localhost.localdomain>, orig_to=<root@localhost>, relay=local, delay=0.13, delays=0.1/0.01/0/0.02, dsn=2.0.0, status=sent (delivered to maildir)
Jan  5 14:29:20 localhost postfix/qmgr[3058]: 7F4439A616: removed
Jan  5 14:57:10 localhost postfix/pickup[5207]: A21B49A618: uid=0 from=<root>
Jan  5 14:57:10 localhost postfix/cleanup[5529]: A21B49A618: message-id=<20150105225710.A21B49A618@localhost.localdomain>
Jan  5 14:57:10 localhost postfix/qmgr[3058]: A21B49A618: from=<root@localhost.localdomain>, size=534, nrcpt=1 (queue active)
Jan  5 14:57:10 localhost postfix/local[5531]: A21B49A618: to=<root@localhost.localdomain>, orig_to=<root>, relay=local, delay=0.38, delays=0.34/0.01/0/0.03, dsn=2.0.0, status=sent (delivered to maildir)
Jan  5 14:57:10 localhost postfix/qmgr[3058]: A21B49A618: removed
Jan  5 15:47:38 localhost postfix/pickup[5207]: F312D9A618: uid=0 from=<root>
Jan  5 15:47:39 localhost postfix/cleanup[5975]: F312D9A618: message-id=<20150105234738.F312D9A618@localhost.localdomain>
Jan  5 15:47:39 localhost postfix/qmgr[3058]: F312D9A618: from=<root@localhost.localdomain>, size=458, nrcpt=1 (queue active)
Jan  5 15:47:39 localhost postfix/local[5977]: F312D9A618: to=<username@localhost.localdomain>, orig_to=<username@localhost>, relay=local, delay=0.12, delays=0.09/0.01/0/0.03, dsn=2.0.0, status=sent (delivered to maildir)
Jan  5 15:47:39 localhost postfix/qmgr[3058]: F312D9A618: removed
Jan  5 15:48:20 localhost postfix/pickup[5207]: A826C9A618: uid=1000 from=<username>
Jan  5 15:48:20 localhost postfix/cleanup[5975]: A826C9A618: message-id=<20150105234820.A826C9A618@localhost.localdomain>
Jan  5 15:48:20 localhost postfix/qmgr[3058]: A826C9A618: from=<username@localhost.localdomain>, size=461, nrcpt=1 (queue active)
Jan  5 15:48:20 localhost postfix/local[5977]: A826C9A618: to=<username@localhost.localdomain>, orig_to=<username@localhost>, relay=local, delay=0.11, delays=0.08/0/0/0.03, dsn=2.0.0, status=sent (delivered to maildir)
Jan  5 15:48:20 localhost postfix/qmgr[3058]: A826C9A618: removed
Jan  5 15:48:29 localhost postfix/pickup[5207]: 54AA19A618: uid=1000 from=<username>
Jan  5 15:48:29 localhost postfix/cleanup[5975]: 54AA19A618: message-id=<20150105234829.54AA19A618@localhost.localdomain>
Jan  5 15:48:29 localhost postfix/qmgr[3058]: 54AA19A618: from=<username@localhost.localdomain>, size=461, nrcpt=1 (queue active)
Jan  5 15:48:29 localhost postfix/local[5977]: 54AA19A618: to=<root@localhost.localdomain>, orig_to=<root@localhost>, relay=local, delay=0.11, delays=0.09/0/0/0.02, dsn=2.0.0, status=sent (delivered to maildir)
Jan  5 15:48:29 localhost postfix/qmgr[3058]: 54AA19A618: removed
Jan  5 15:52:03 localhost postfix/pickup[5207]: C756E9A618: uid=0 from=<root>
Jan  5 15:52:03 localhost postfix/cleanup[6074]: C756E9A618: message-id=<20150105235203.C756E9A618@localhost.localdomain>
Jan  5 15:52:03 localhost postfix/qmgr[3058]: C756E9A618: from=<root@localhost.localdomain>, size=491, nrcpt=1 (queue active)
Jan  5 15:52:03 localhost postfix/local[6076]: C756E9A618: to=<root@localhost.localdomain>, orig_to=<root@localhost>, relay=local, delay=0.13, delays=0.09/0.01/0/0.03, dsn=2.0.0, status=sent (delivered to maildir)
Jan  5 15:52:03 localhost postfix/qmgr[3058]: C756E9A618: removed
Jan  5 16:02:36 localhost postfix/smtpd[6213]: connect from localhost.localdomain[127.0.0.1]
Jan  5 16:04:26 localhost postfix/smtpd[6213]: disconnect from localhost.localdomain[127.0.0.1]  

日誌說delivered to maildir。我是否使用錯誤的語法來訪問maildir內容?

另外,main.cf如下(注意它需要允許 localhost 帳戶相互發送電子郵件):

queue_directory = /var/spool/postfix
command_directory = /usr/sbin
daemon_directory = /usr/libexec/postfix
data_directory = /var/lib/postfix
mail_owner = postfix
myorigin = localhost
inet_interfaces = localhost
inet_protocols = all
unknown_local_recipient_reject_code = 550
mynetworks = 127.0.0.0/8 [::ffff:127.0.0.0]/104 [::1]/128
relayhost = 
alias_maps = hash:/etc/aliases
alias_database = hash:/etc/aliases
home_mailbox = Maildir/
mailbox_command = 
debug_peer_level = 2
debugger_command =
   PATH=/bin:/usr/bin:/usr/local/bin:/usr/X11R6/bin
   ddd $daemon_directory/$process_name $process_id & sleep 5
sendmail_path = /usr/sbin/sendmail.postfix
newaliases_path = /usr/bin/newaliases.postfix
mailq_path = /usr/bin/mailq.postfix
setgid_group = postdrop
html_directory = no
manpage_directory = /usr/share/man
sample_directory = /usr/share/doc/postfix-2.10.1/samples
readme_directory = /usr/share/doc/postfix-2.10.1/README_FILES

我究竟做錯了什麼?

編輯:

根據masegaloeh的建議,我nano ~/.mailrc在保存之前輸入並添加了以下內容:

set MAIL=/home/root/Maildir
set folder=mail

接下來,我輸入mailx了 ,但終端回復了No mail for root。因此,我創建了一封新電子郵件,其中包含以下內容:

[root@localhost ~]# mailx
No mail for root
[root@localhost ~]# mailx root@localhost
Subject: another 905pm test.
gonna try again now.
EOT
[root@localhost ~]# mailx
No mail for root

如您所見,無法閱讀我剛剛發送的電子郵件。我究竟做錯了什麼?

預設情況下,mailx 將搜尋讀取的 mbox 文件/var/spool/mail/$username。您可以使用以下命令查看它(感謝beginlinux.com網站

$ set | grep -i mail
MAIL=/var/spool/mail/myuser
MAILCHECK=60

當您更改home_mailboxpostfix 中的參數時,您需要調整 mailx 配置,以便它將在新位置搜尋郵件。使用home_mailbox = Maildir/後,postfix 會將電子郵件儲存在 Maildir 目錄中**,與使用者主目錄相對**。

來自 postfix man postconf的片段

home_mailbox(預設:空)

相對於 local(8) 使用者主目錄的郵箱文件的可選路徑名。

指定以“/”結尾的路徑名以進行 qmail 樣式的傳遞。

因此,您的電子郵件將儲存在 中$HOME/Maildir/,其中 $HOME 是您的主目錄。對於 root,他的主目錄是/root/; 對於其他使用者,他的主目錄通常位於/home/otheruser/. 請參閱unix.SE 中的muru解釋: Root /home Directory vs ~ (tilde)

在您的情況下,您需要編輯~/.mailrc並添加這兩行

set MAIL=/root/Maildir
set folder=mail

參考資料 -> Fedora 論壇:~/.mailrc 更改

引用自:https://serverfault.com/questions/656514