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”.
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:
Make a new gmail account. This is the address you will use to send messages to you wish to have delayed.
Have your mail fetcher put all messages to this address into it’s own independent maildir (say
Set up mutt (or sendmail, if you wish) with the account credentials. An example
muttrc would look like:
set from = "Delay Email <email@example.com> set smtp_url = "smtp://firstname.lastname@example.org@smtp.gmail.com:587/" set smtp_pass = "PASSWORD"
Make the directory
Put the following script in your
#!/bin/bash # delayemail.sh # delay an email for sending later # directory where mail to be sent later is stored MAILDIR=$(HOME)/Mail/delay # directory for temporary message file ATTMP=$(HOME)/.at # check that these two directories exist if [ ! -d $MAILDIR ]; then echo "$MAILDIR does not exist, create directory or set \$MAILDIR" exit fi if [ ! -d $ATTMP]; then echo "$ATTMP does not exist, create directory or set \$ATTMP" exit fi # 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) do 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 done
Add a cronjob calling this script every so many minutes
*/15 * * * * ~/bin/delayemail.sh
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> MESSAGE BODY ..
delayemail.sh will then queue up the message for delivery using