![无法从 centos 7 命令行查看 postfix 电子邮件,为什么?](https://linux22.com/image/35854/%E6%97%A0%E6%B3%95%E4%BB%8E%20centos%207%20%E5%91%BD%E4%BB%A4%E8%A1%8C%E6%9F%A5%E7%9C%8B%20postfix%20%E7%94%B5%E5%AD%90%E9%82%AE%E4%BB%B6%EF%BC%8C%E4%B8%BA%E4%BB%80%E4%B9%88%EF%BC%9F.png)
我已经postfix
安装在开发盒上并使用了其他帖子中的参数配置postfix
为localhost
仅工作。但另一篇文章没有解释如何从命令行发送电子邮件或查看收到的电子邮件。我有用于发送/接收电子邮件的更高级别代码smtp
,但我希望能够首先从命令行执行此操作,以便postfix
在开始测试更高级别代码之前验证其是否正常工作。我已经尝试了几次,似乎正在发送电子邮件,但我找不到已发送的电子邮件。如何确认电子邮件已发送并从命令行读取电子邮件?
编辑#1:
我MAIL=/home/root/Maildir
在终端中输入,然后按回车键,然后输入mail
并按回车键。我在root
帐户中执行此操作并再次在username
帐户中执行此操作。这显示了帐户中的旧电子邮件列表root
,因此我登录了该username
帐户并输入以下内容以将电子邮件发送username
至root
:
sendmail root@localhost <<EOF
subject:This is a test
from:username@localhost
Body message here...
EOF
前面的代码导致另一个命令提示符没有错误。但是,当我重新登录root
并mail
再次输入以检查邮件时,新电子邮件并未与旧电子邮件一起列出。
另外,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@localhost
和username@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]。
[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