Centos

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

  • January 7, 2015

我已經postfix安裝在一個開發盒上,並且我使用了這個其他文章中的參數來配置只postfix在它上面工作localhost。但是另一篇文章沒有解釋如何從命令行發送電子郵件或查看收到的電子郵件。我有用於發送/接收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=<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上面的問題?

編輯#3

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

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

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

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

如果您確實想從命令行發送和接收電子郵件,那麼您需要郵件使用者代理 (MUA) 而不是郵件傳輸代理 (MTA)

$$ 3 $$. 穆特$$ 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#Text-based $$ 3 $$ http://en.wikipedia.org/wiki/Email_agent_%28infrastructure%29

引用自:https://unix.stackexchange.com/questions/177610