Send E-Mails To The Future | srgdev.com

Send E-Mails To The Future

A linux shell script to send email messages/reminders at some point in the future. Works on linux boxes with a functional mail server.Linux, E-Mail, Bash Download (1KB): email-reminder.sh

About

This shell script uses linux's at command to schedule the mail command. Queued emails are not affected by system reboots, and the atq command can be used to view all pending tasks. The script takes 5 parameters: From_email, To_email, Subject, Message and Time_Date. The Time_Date format is fairly flexible: the time is followed by an optional date and accepts forms like 17:00 Jul 3 2031 or at 1pm tomorrow or even now + 5 days. If the Time_Date parameter is omitted the message is sent right away.

Usage example:
./email-reminder.sh \
-f from_email@example.com \
-t to_email@example.com \
-s "Appointment Reminder" \
-m "You have a very important appointment at 10:30AM tomorrow, August 23rd" \
-w "10:00AM  08/22/2032"
				

email-reminder.sh

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#!/bin/bash FROM='' TO='' SUBJECT='' MSG='' AT='now' usage() { echo " Usage: $0 OPTIONS [-w \"10:45AM 03/14/2042\"] -f From Address -t To Address -s Subject -m Message -w When to send (optional) @see 'man at' " } while getopts ':f:t:s:m:w:h' flag; do case "${flag}" in f) FROM="${OPTARG}" ;; t) TO="${OPTARG}" ;; s) SUBJECT="${OPTARG}" ;; m) MSG="${OPTARG}" ;; w) AT="${OPTARG}" ;; h) usage; exit;; \?) echo -e "\nUnknown option: -$OPTARG" >&2;usage; exit 1;; :) echo -e "\nMissing argument for option -$OPTARG" >&2;usage; exit 1;; esac done if [ ! "$FROM" ] || [ ! "$TO" ] || [ ! "$SUBJECT" ] || [ ! "$MSG" ] then usage exit 1 fi echo "/usr/bin/mail -t <<EMAILMSG To: $TO From: $FROM Subject: $SUBJECT Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset=UTF-8 $MSG EMAILMSG " | at ${AT}