Sometimes my users accidentally delete their .forward files, and then Postfix falls back to delivering mails to /var/spool/mail. I would like it to instead put the message in the Hold or Deferred queue so that I can notice the situation and help the user fix their .forward file. Is this possible?
1 Answer
So I couldn't find any obvious way to do it. In theory I think that it should be possible to use a transport to get it to work but I didn't manage to have it actually hold or defer the mails.
The way I solved it (which is very hacky) is to use the mailbox_command
variable in the main.cf
file. It is intended to specify an external command to use instead of mailbox delivery. As it turns out it also listens smtp status codes, which can be be used to force the mail to be held on the server. First, add the following line in main.cf
:
mailbox_command = /etc/postfix/defer-mail
And create the file /etc/postfix/defer-mail
and have it look something like this:
#!/bin/bash
echo "4.3.0 Mail expansion not available (missing .forward file)"
exit 1
This will put mails in your deferred
queue, from which it is then possible to move into the hold
queue.
.forward
file, why don't you (re-) configure Postfix so that mail gets delivered correctly by default?.forward
file to for instance ensure a Maildir/ format, but regardless: normally the presence of a .forward is an exception rather than the default and the absence of such a file should result in correct delivery. - SMTP standards are such that anything that results in delivery errors, such as an incorrectly formatted.forward
, should return a delivery failure to the original sender. - In short I don't think you can arbitrarily put the mail on hold..forward
file, so it hopefully it isn't an exception here. Also, in Postfix there is literally a transport named defer, which I thought would work, but it turns out it didn't. Anyway I found out an alternative (and a bit hacky) way to solve it.