無法從 centos 7 命令列查看 postfix 電子郵件,為什麼?

無法從 centos 7 命令列查看 postfix 電子郵件,為什麼?

我已經postfix安裝在開發盒上並使用了其他帖子中的參數配置postfixlocalhost僅工作。但另一篇文章並沒有解釋如何從命令列發送電子郵件或查看收到的電子郵件。我有用於發送/接收電子郵件的更高級別代碼smtp,但我希望能夠首先從命令行執行此操作,以便postfix在開始測試更高級別代碼之前驗證其是否正常工作。我已經嘗試了幾次,似乎正在發送電子郵件,但我找不到已發送的電子郵件。如何確認電子郵件已發送並從命令列讀取電子郵件?

編輯#1:

MAIL=/home/root/Maildir在終端機中輸入,然後按回車鍵,然後輸入mail並按回車鍵。我在root帳戶中執行此操作並再次在username帳戶中執行此操作。這顯示了帳戶中的舊電子郵件列表root,因此我登入該username帳戶並輸入以下內容以將電子郵件發送usernameroot

sendmail root@localhost <<EOF
subject:This is a test
from:username@localhost
Body message here...
EOF

前面的程式碼導致另一個命令提示字元沒有錯誤。但是,當我重新登入rootmail再次輸入以檢查郵件時,新電子郵件並未與舊電子郵件一起列出。

另外,main.cf如下:

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

我究竟做錯了什麼?

編輯#2:

根據 IanMcGowan 的建議,我檢查了它mailx是否已經安裝。然後我用了本教程使用命令測試發送和接收電子郵件mailx,但我也無法閱讀新發送的電子郵件。我認為這是一個配置問題。我使用的電子郵件地址如root@localhostusername@localhost

telnet localhost 25結果是:

Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
220 localhost.localdomain ESMTP Postfix

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=<[email protected]>, 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=<[email protected]>, 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=<[email protected]>
Jan  5 14:29:20 localhost postfix/qmgr[3058]: 7F4439A616: from=<[email protected]>, size=334, nrcpt=1 (queue active)
Jan  5 14:29:20 localhost postfix/local[5271]: 7F4439A616: to=<[email protected]>, 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=<[email protected]>
Jan  5 14:57:10 localhost postfix/qmgr[3058]: A21B49A618: from=<[email protected]>, size=534, nrcpt=1 (queue active)
Jan  5 14:57:10 localhost postfix/local[5531]: A21B49A618: to=<[email protected]>, 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=<[email protected]>
Jan  5 15:47:39 localhost postfix/qmgr[3058]: F312D9A618: from=<[email protected]>, size=458, nrcpt=1 (queue active)
Jan  5 15:47:39 localhost postfix/local[5977]: F312D9A618: to=<[email protected]>, 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=<[email protected]>
Jan  5 15:48:20 localhost postfix/qmgr[3058]: A826C9A618: from=<[email protected]>, size=461, nrcpt=1 (queue active)
Jan  5 15:48:20 localhost postfix/local[5977]: A826C9A618: to=<[email protected]>, 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=<[email protected]>
Jan  5 15:48:29 localhost postfix/qmgr[3058]: 54AA19A618: from=<[email protected]>, size=461, nrcpt=1 (queue active)
Jan  5 15:48:29 localhost postfix/local[5977]: 54AA19A618: to=<[email protected]>, 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=<[email protected]>
Jan  5 15:52:03 localhost postfix/qmgr[3058]: C756E9A618: from=<[email protected]>, size=491, nrcpt=1 (queue active)
Jan  5 15:52:03 localhost postfix/local[6076]: C756E9A618: to=<[email protected]>, 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

編輯#3

我輸入nano /var/spool/mail/root並能夠查看當我以 root 身份登入並輸入mail或時顯示的舊電子郵件mailx。但新電子郵件並不位於此處。這些電子郵件是自動發送的,似乎是postfix配置為使用/Maildir結構之前的遺物。

答案1

除非您有特定要求來移動您的郵件儲存;只需將配置恢復為預設值即可。

該設定儲存您的電子郵件/var/spool/mail/<username>而不是您的home電子郵件,這意味著您安裝的任何 MUA 都知道在哪裡可以找到它,而無需任何重新配置​​。

答案2

如果您只是測試管道,那麼從命令列使用 mail/sendmail 就可以正常工作(telnet localhost 25 也可以)。如果您沒有收到該郵件,請檢查 /var/log 是否有錯誤並發布這些錯誤以協助解決。

如果您確實想從命令列傳送和接收電子郵件,那麼您需要郵件使用者代理程式 (MUA),而不是郵件傳輸代理程式 (MTA)[3]。 Mutt[1] 是常見的答案,儘管還有其他優秀的命令列用戶端可供選擇[2]。

[1]https://access.redhat.com/documentation/en-US/Red_Hat_Enterprise_Linux/3/html/Step_by_Step_Guide/s1-eclients-textmail.html

[2]http://en.wikipedia.org/wiki/List_of_email_clients#基於文本

[3]http://en.wikipedia.org/wiki/Email_agent_%28infrastructure%29

答案3

MAIL=/home/root/Maildir改成MAIL=/root/Maildir

相關內容