我遇到的问题就是 postfix 无法将电子邮件发送到我的主目录。我有一个正在运行的 Ubuntu 14.04 服务器,由于加密主驱动器出现一些问题,postfix 无法访问我的 Maildir。
在 mail.log 中我收到以下错误:
Apr 4 09:51:35 server postfix/smtpd[13658]: connect from localhost[127.0.0.1]
Apr 4 09:51:35 server postfix/smtpd[13658]: 6FE354360A18: client=localhost[127.0.0.1]
Apr 4 09:51:35 server postfix/cleanup[13661]: 6FE354360A18: message-id=<[email protected]>
Apr 4 09:51:36 server postfix/smtpd[13658]: disconnect from localhost[127.0.0.1]
Apr 4 09:51:36 server postfix/qmgr[2085]: 6FE354360A18: from=<[email protected]>, size=87170, nrcpt=1 (queue active)
Apr 4 09:51:36 server postfix/local[13664]: warning: maildir access problem for UID/GID=1000/1000: create maildir file /home/user/Maildir/tmp/1459756296.P13664.server: Permission denied
Apr 4 09:51:36 server postfix/local[13664]: warning: perhaps you need to create the maildirs in advance
Apr 4 09:51:36 server postfix/local[13664]: 6FE354360A18: to=<andreas@localhost>, relay=local, delay=0.95, delays=0.88/0.01/0/0.06, dsn=5.2.0, status=bounced (maildir delivery failed: create maildir file /home/user/Maildir/tmp/1459756296.P13664.server: Permission denied)
Apr 4 09:51:36 server postfix/cleanup[13661]: 668984360A1A: message-id=<20160404075136.668984360A1A@server>
Apr 4 09:51:36 server postfix/bounce[13665]: 6FE354360A18: sender non-delivery notification: 668984360A1A
Apr 4 09:51:36 server postfix/qmgr[2085]: 668984360A1A: from=<>, size=4544, nrcpt=1 (queue active)
Apr 4 09:51:36 server postfix/qmgr[2085]: 6FE354360A18: removed
Apr 4 09:51:36 server postfix/smtp[13666]: 668984360A1A: to=<[email protected]>, relay=smtp.otherserver.org:587, delay=0.54, delays=0.19/0.05/0.23/0.07, dsn=2.0.0, status=sent (250 2.0.0 Ok: queued as C979113D0138)
Apr 4 09:51:36 server postfix/qmgr[2085]: 668984360A1A: removed
我重新启动了服务器,希望在 /var/mail/xxx 中找到在此期间发送的电子邮件,但只有一个带有我的用户名的零字节文件。
这是否意味着我在此期间收到的邮件会丢失?如何配置保存邮件?
编辑:mailq 显示空邮件队列。编辑 2:添加了更多日志输出
答案1
它应该在邮件队列中
发送简单电子邮件
# echo "Hello world" | swaks -4 --server smtp.example.net --from [email protected] --to [email protected] --h-Subject "Test message" --body -
=== Trying smtp.example.net:25...
=== Connected to smtp.example.net.
<- 220 smtp.example.net ESMTP Postfix
-> EHLO tl-resin-node1.example.net
<- 250-smtp.example.net
<- 250-PIPELINING
<- 250-SIZE 10240000
<- 250-VRFY
<- 250-ETRN
<- 250-AUTH LOGIN PLAIN
<- 250-ENHANCEDSTATUSCODES
<- 250-8BITMIME
<- 250 DSN
-> MAIL FROM:<[email protected]>
<- 250 2.1.0 Ok
-> RCPT TO:<[email protected]>
<- 250 2.1.5 Ok
-> DATA
<- 354 End data with <CR><LF>.<CR><LF>
-> Date: Tue, 05 Apr 2016 03:45:43 -0400
-> To: [email protected]
-> From: [email protected]
-> Subject: Test message
-> X-Mailer: swaks v20130209.0 jetmore.org/john/code/swaks/
->
-> Hello world
->
->
-> .
<- 250 2.0.0 Ok: queued as 581271C1811
-> QUIT
<- 221 2.0.0 Bye
=== Connection closed with remote host.
检查 smtp.example.net 上的邮件日志
# cat /var/log/maillog | grep 581271C1811
Apr 5 07:45:41 ci postfix/smtpd[31639]: 581271C1811: client=smtp.example.com[192.168.88.130]
Apr 5 07:45:41 ci postfix/cleanup[31642]: 581271C1811: message-id=<>
Apr 5 07:45:41 ci postfix/qmgr[31633]: 581271C1811: from=<[email protected]>, size=389, nrcpt=1 (queue active)
Apr 5 07:45:41 ci postfix/virtual[31643]: 581271C1811: to=<[email protected]>, relay=virtual, delay=0.07, delays=0.02/0.01/0/0.04, dsn=4.2.0, status=deferred (maildir delivery failed: create maildir file /var/mail/virtual/example.net/[email protected]/tmp/1459842341.P31643.ci.example.net: Permission denied)
检查邮件日志
# postqueue -p
-Queue ID- --Size-- ----Arrival Time---- -Sender/Recipient-------
581271C1811 389 Tue Apr 5 07:45:41 [email protected]
(maildir delivery failed: create maildir file /var/mail/virtual/example.net/[email protected]/tmp/1459842341.P31643.ci.example.net: Permission denied)
[email protected]
-- 1 Kbytes in 1 Request.
修复权限
# ls -la
total 16
drwxr-xr-x 4 alex alex 4096 Mar 18 14:32 .
drwxrwxr-x. 3 root mail 4096 Apr 2 03:35 ..
drwx------ 3 virtual virtual 4096 Mar 15 09:18 example.com
drwx------ 3 root virtual 4096 Mar 18 14:32 example.net
# chown virtual:virtual example.net
刷新邮件队列并再次检查邮件日志
# postqueue -f
Apr 5 07:49:01 ci postfix/anvil[31640]: statistics: max cache size 1 at Apr 5 07:45:41
Apr 5 07:49:29 ci postfix/qmgr[31633]: 581271C1811: from=<[email protected]>, size=389, nrcpt=1 (queue active)
Apr 5 07:49:29 ci postfix/virtual[31894]: 581271C1811: to=<[email protected]>, relay=virtual, delay=228, delays=228/0.02/0/0.06, dsn=2.0.0, status=sent (delivered to maildir)
Apr 5 07:49:29 ci postfix/qmgr[31633]: 581271C1811: removed
答案2
TLDR:根据 postfix 的默认行为,您的电子邮件将被退回(即,您的发件人将收到未送达消息)并且 postfix 甚至不会在队列中保留该电子邮件。
根据 mercury 和 ALex_hha 的日志,我可以得出结论,邮件通过以下方式传递时的行为有所不同:虚拟守护进程(ALex_hha 案例)或本地守护进程(水星案例)。当虚拟守护进程由于权限问题而无法发送电子邮件时,它将使用延迟电子邮件(软退回)功能,因此电子邮件将保留在队列中。
Apr 5 07:45:41 ci postfix/virtual[31643]: 581271C1811: to=<[email protected]>, relay=virtual, delay=0.07, delays=0.02/0.01/0/0.04, dsn=4.2.0, status=deferred (maildir delivery failed: create maildir file /var/mail/virtual/example.net/[email protected]/tmp/1459842341.P31643.ci.example.net: Permission denied)
在另一种情况下,本地守护进程将退回电子邮件(硬退回),因此电子邮件不会留在队列中。
Apr 4 09:51:36 server postfix/local[13664]: 6FE354360A18: to=<andreas@localhost>, relay=local, delay=0.95, delays=0.88/0.01/0/0.06, dsn=5.2.0, status=bounced (maildir delivery failed: create maildir file /home/user/Maildir/tmp/1459756296.P13664.server: Permission denied)
当您根据dsb_simple
函数查看 virtual/maildir.c 和 local/maildir.c 的源代码时,也可以看到这种行为。
本地/maildir.c
dsb_simple(why, mbox_dsn(errno, "5.2.0"),
"create maildir file %s: %m", tmpfile);
虚拟/maildir.c
dsb_simple(why, mbox_dsn(errno, "4.2.0"),
"create maildir file %s: %m", tmpfile);
在这种情况下我该如何防止硬退回?
据我所知,根据上述源代码,此行为无法通过 postfix 配置主配置文件。但尝试设置soft_bounce = yes
,但要注意全局影响,当你启用此功能。