Hi all, I have a Debian linux server and am using Postfix as my MTA configured up to structure e-mail server side in Maildir format (as opposed to mbox). Therefore, and for the purposes of this brief note, a new e-mail message to me on my server appears as a new file in /home/mdo/Maildir/new
As I only periodically check my personal e-mail accounts, whereas I use and have my mobile phone with me at all times and can receive and process SMS messages interactively, I wanted an automated script to process new e-mail messages sent to me and to then send me an SMS message containing the e-mail message sender (mail "from" e-mail address) and the e-mail message subject line (and specifically not what might be a large e-mail message body containing, for example, attachments). Based on this information, I can then quickly decide whether my personal e-mail needs action immediately, or whether it can wait.
I have written a quick and dirty script for this purpose and include an easy to follow version below. This script is considerably more verbose than it needs to be as one of my aims is to make it easy to configure for alternative purposes by those that perhaps aren't that familiar with shell scripting. The script below is invoked/executed every 10mins through a cron job.
Any questions, feel free to drop me a line.
Mike O'Shea
http://www.strychnine.co.uk e-mail:
mdo@strychnine.co.uk
#!/bin/sh
#
#go and get all the current new email messages, Maildir and not mbox format and
#store all the new e-mail message file names in a new file named 'currentNewEMail.txt'
find /home/mdo/Maildir/new/* -type f -print 2>/dev/null | sort>currentNewEMail.txt
#just make sure that a 'priorNewEmail.txt' exists. This will contain a list of all the new e-mail (files) that the
#script found the last time it was run. Therefore 'priorNewEmail.txt' will probably exist however if it doesn't, then
#a 'touch' will create an empty one
touch priorNewEMail.txt
#and now, work out the new e-mail since last time this utility was run
#and store this in 'newEmail.txt' (ie the difference between the two). This way, if two new e-mail message are
#received, the SMS recipient will receive two SMS messages. If a third new e-mail message is received, the
#SMS recipient will receive just one further SMS message
comm -23 currentNewEMail.txt priorNewEMail.txt >newEMail.txt
for line in `cat newEMail.txt`;do
echo 'New mail: ' > newEMailFrom.txt
grep '^From: ' $line >> newEMailFrom.txt
grep '^Subject: ' $line >> newEMailFrom.txt
mutt -s "New e-mail in your inbox;" 440123456789.yourusername.yourpassword@messaging.intellisoftware.co.uk < newEMailFrom.txt
#don't forget to change your phone number above, and insert your IntelliSoftware username and password
done
mv -f currentNewEMail.txt priorNewEMail.txt
Edited by user
2011-10-10T10:01:24Z
|
Reason: Not specified