2018/11/30: Reminder emails

Be honest, who has never written an email to themselves to not forget something that isn't immediately actionable? (I'm thinking of things that could become actionable later the same day, e.g., when at home and having access to other resources; so usually it is not considered worth adding to the diary). And then there are mails left in the INBOX, because there is still something to do, but again, it cannot be done right now.

I recently decided that, if I find myself using my mailbox as a todo-list anyway, I can as well do so properly with only mails in it that are immediately actionable. (I noticed that I tend to get blind for mails sitting in INBOX for too long, thus forgetting about them when I could actually do something.) The missing primitive needed is a way of saying to an email "Go away, and come back to my INBOX at that date and time". The "Go away" part is easy, it's simply deleting (or archiving; deduplicating mails by Message-Id is a standard operation in any decent mail reader). And the sending a mail to my self to arrive only at a specified point in time also turned out to be surprisingly simple.

Our mail setup has a local mail domain, not reachable from the outside. So I have an email address where I can bounce mails to (or send, for self-written reminders) that need to come back to be at a specified time in the future, without having to worry about others being able to send mails to that magic mail address as well. Actually, it's a family of email addresses thanks to qmail's way of splitting the local part at minus signs and searching for default instructions by dropping parts from the end till one is found. So a .qmail-file called linta+local-aehlig-reminder-default will handle all emails to addresses of the form aehlig-reminder-MMDDhhmm@linta.local and the MMDDhhmm-part is conveniently stored in the environment variable EXT4. Now, scheduling can be done using at(1), rsmtp is part of my mail infrastructure anyway, and reformating as BSMTP is easy, especially with hard-coded recipient and return path.

Hence, all it needed was a file linta+local-aehlig-reminder-default with content


|/home/aehlig/.qmail.d/mail-scripts/do-reminder

and the following do-reminder script. (Careful, this script is "works for me" not a productionized service; beware of hard-coded paths and email-addresses.)
#!/usr/bin/perl -w

use strict;
my $id = time() + ".$$";

my $bsmtpfile = "/home/aehlig/tmp/reminders/R-$id.bsmtp";

open (BSMTP, ">", $bsmtpfile) or die "Failed to open $bsmtpfile ($!)";

print BSMTP "HELO reminder.aehlig.linta.de\n";
print BSMTP "MAIL FROM: aehlig-direct\@linta.local\n";
print BSMTP "RCPT TO: aehlig-notify-and-direct\@linta.local\n";
print BSMTP "DATA\n";

while(<STDIN>) {
 s/^\./\.\./;
 print BSMTP $_;
};

print BSMTP ".\n";
print BSMTP "QUIT\n";

close(BSMTP) or die "Failed to cloase $bsmtpfile ($!)";

if ($ENV{'EXT4'} =~ /^[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]$/ ) {
 open (AT, "|-", "at", "-t", $ENV{'EXT4'}) or die "Failed to open at";
} else {
 open (AT, "|-", "batch") or die "Failed to open at";
}

print AT "/usr/local/bin/rsmtp < $bsmtpfile && rm $bsmtpfile";

close(AT) or die "Failed to close at";
download



Cross-referenced by: