home of the madduck/ blog/
Delaying mail

One thing I really miss about email as we know it is the feature to deliver a mail at a specified point in time, not necessarily now.

Conceptually, this could be done quite easily: have an alias maildelay deliver to a script, which parses the envelope recipient of the form:

maildelay+2006.06.06.2000=madduck=debian.org@my.mail.relay

The script would drop the mail into a temporary file, removing the control information from the recipient headers:

s|[^=]*=(.+)=(.+)|\1@\2|

and set the file's modification date to the requested delivery date. Then have a daemon periodically scan the directory and pass expired files to /usr/sbin/sendmail.

Michael Tokarev also offers an interesting approach: using Postfix header_checks, he suggests putting messages that contain a header such as X-Delay-Send on hold:

/^X-Delay-Send:/ FILTER hold:

Then, scan the hold queue and set the modification date of the appropriate files to the requested time to let Postfix's qmgr handle the delivery around that time.

Of course, I am not supposed to roam about in /var/spool/postfix/deferred, less change any inodes, thus this method right now is not more than a nice idea (I did submit a feature request to Postfix; it doesn't look like it'll be accepted.).

Regardless, both approaches are effectively open relays and I am not too inclined to do anything about that. So, moving on...

Another method would be to write a policy daemon that returns a 4xx status message until the time specified in the email. Of course, this has the problem of unpredictability, so the mail could be delayed several hours longer than requested. But given the requirement that I'd like to turn my laptop (the submitting MTA) off and still have the mail delivered, the solution may be a second MTA on my SMTP relay (perhaps on port 587/tcp), which takes care of all TLS and SASL submissions and has a predictable retry period.

If you have any thoughts (or existing solutions), please let me know!