delayemail.sh is a simple script which allows an email to be scheduled to be sent at a later date. I mostly use it as a reminder service, but it often comes in handy if you (like me) like to operate in “batch mode”.

Operation of delayemail.sh is simple, but it assumes you have a maildir-like email setup on a computer which is more or less on all the time. See my email page for how I implement this email business.


The recommended setup is as follows:

  1. Make a new gmail account. This is the address you will use to send messages to you wish to have delayed.

  2. Have your mail fetcher put all messages to this address into it’s own independent maildir (say $HOME/Mail/delay).

  3. Set up mutt (or sendmail, if you wish) with the account credentials. An example muttrc would look like:

    set from = "Delay Email <delay.email.example@gmail.com>
    set smtp_url = "smtp://delay.email.example@gmail.com@smtp.gmail.com:587/"
    set smtp_pass = "PASSWORD"
  4. Make the directory $HOME/.at.

  5. Put the following script in your $PATH

    # delayemail.sh
    # delay an email for sending later
    # directory where mail to be sent later is stored
    # directory for temporary message file
    # check that these two directories exist
    if [ ! -d $MAILDIR ]; then
        echo "$MAILDIR does not exist, create directory or set \$MAILDIR"
    if [ ! -d $ATTMP]; then
        echo "$ATTMP does not exist, create directory or set \$ATTMP"
    # for all messages in this directory, construct message and schedule it to
    # be sent at a later date with at
    for FILE in $(find $MAILDIR -type f)
        TO=`cat $FILE | sed '1,/^$/ d' | sed '1q;d'`
        SUBJECT=`grep '^Subject: ' $FILE | sed -e "s/^Subject: //"`
        SEND=`cat $FILE | sed '1,/^$/ d' | sed '2q;d'`
        SEND=`date --date="$SEND" +"%H:%M %D"`
        sed '1,/^$/ d' $FILE | sed '1,/^$/ d' > ~/.at/delay.$$
        echo "mutt -s \"$SUBJECT\" $TO < ~/.at/delay.$$ ; rm ~/.at/delay.$$ " | at $SEND
        rm $FILE
  6. Add a cronjob calling this script every so many minutes

    */15 * * * * ~/bin/delayemail.sh
  7. Send a message to yourself with the following format:

    <first line who you want the message to really go to>
    <second line fuzzy date at which it should be send>

delayemail.sh will then queue up the message for delivery using at.