无法从 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/MaildirMAIL=/root/Maildir

相关内容