Automatic Email Reminders

June 22, 2009

Many services seem to provide automatic email reminders these days – notably Google Calendar; however what I need is something that can send me daily reminders about things, and setting up a Google calendar with daily repeats seems an altogether inelegant solution. Virgin Media operates a throttling policy in which downloading is limited between 10am and 3pm, and again between 4pm and 9pm. As far as I’m concerned, all this means is I need to make sure I’m not downloading much between those times. I thought of setting up my various alarm clocks and watches to ring at 10am, 3pm, 4pm and 9pm to remind me – but considering I’d have to use four different devices (none of my alarm clocks support multiple alarms) and the fact that it would all be useless if I’m not at home, the best solution is to use a daily email reminder which would alert me even if I’m working off my laptop at school (for example).

I also jumped at the opportunity to find out more about Linux and PHP; besides I didn’t want to sign up for several free email reminder services hunting for a good one so opted simply to write my own. For the sake of anyone attempting to implement any of the features of PHP and Linux I used, here is my solution which can essentially be broken down into four parts:

1. Emailing script

It was fairly easy to find out how to send an email via SMTP in PHP so I set up a script to connect to my gmail and send an email from there to myself. After turning it all into a function, in accordance with the modular approach to development, I was ready to proceed.

2. Scheduler

This was more difficult. PHP can’t by itself do anything on a schedule so it was necessary to delve into Debian’s scheduling system. I tried to look up how to make the damn thing work and eventually found (amongst other irrelevant info – hurry up Wolfram Alpha and add support for coders!) how to use it. It seems like cron is already pre-installed upon Debian installation, and is constantly running as a daemon. It checks a file every minute to check whether it should be executing a scheduled task. To edit this file you type ‘crontab -e’ and get a plaintext editing interface (looks like vi). The format of the file is a list of lines, each one representing a scheduled task. Each line’s format is:

[minute : int] [hour : int] [day of month : int] [month of year : int] [year : int] [script pathname : string]

So to run the program ‘rtorrent’ at 17:30 every 3rd of the month, you go:

30 17 3 * * rtorrent

Asterisks are, as always, wildcards. To execute a process every minute, the first 5 terms look like ‘* * * * *’. There is a slight problem with this: you can’t use vi from a PHP script (at least it’s not possible using exec). It turns out there’s an alternative way of using crontab – by importing a file. So the command looks like:

crontab foo.txt

Great. So the PHP script creates a text file containing the new line then executes a command to add that file to the cron file. Eventually I set it to run the script every minute and have the script itself check for whether it should be doing anything by referencing a MySQL database.

So in the end the PHP looked like this:

$fh = fopen(“foo.txt”, ‘w’) or die(“can’t open file”);
$stringData = “* * * * * /opt/lampp/bin/php /opt/lampp/htdocs/php/ereminders/s_mail.php &> /dev/null\n”;
fwrite($fh, $stringData);
fclose($fh);
exec(“crontab foo.txt” . ‘ 2>&1′, $output);

The &> /dev/null is just to stop it ‘helpfully’ sending email to root every time it runs (i.e. every minute) containing a log of exactly what happened.

3. Database

It’s a fairly simple MySQL thing – nothing fancy. I wrote a nice function in PHP to tabulate the results of a query which I use in my screenshot. It’s a single table and I haven’t bothered to normalise it or anything. Nothing to see here. Move on.

4. Admin panel

This was, like with most good things, the final stage of development. I was also getting lazy and bored so it’s pretty rudimentary; I wrote it just so I don’t have to go into PHPMyAdmin to change things. It makes use of that rather neat ‘tabulate’ function that I had written which tabulates the MySQL query. The var_dump is the contents of the cron file.

Final thoughts

In hindsight, this is pretty good for two hours’ work, especially considering about half an hour was spent writing scripts to automate things from an admin panel. I’ve also actually found it quite useful (pardon the surprise) – the other day I wanted to download an episode of Lost Windows 7 but the throttling period had already started and that one download would probably have pushed me over the download limit. At exactly 9pm I got an email reminding me to download so was able to watch the episode install the OS that very night. Though I doubt it’ll be much use to anyone other than me since there exist systems out there that do the same thing, just much better (probably).

๏̯͡๏﴿


A word on email hoaxes and Mediafire

February 19, 2009

I was actually surprised both my parents were taken in by this one. This PDF file was being circulated all over ‘the tubes’ via email and both my parents fell for it and advised me to spam my contact list. I have no intention of going through the whole thing pointing out at every paragraph why it’s a hoax – it seems so obvious anyway – but this website does it fairly well for a similar email hoax. However I will say one thing which I think is highly important: please please *please* for all of you out there reading this who don’t already know/do:

If you see the words:

PLEASE FORWARD THIS WARNING AMONG ALL YOUR CONTACTS

especially if they are in block capitals, think twice before obeying automatically and unthinkingly! It is unbelievably annoying to receive chain emails, and even if you don’t think such inbox annoyances are remotely vexatious, your friends may differ with you: you are effectively spamming them.

If you already knew that, sorry for the rant – I get rather emotional about such things. If ever in doubt, it’s probably worth checking what hoaxslayer has to say.

Mediafire Logo

Meanwhile, onto Mediafire, the file sharing service I’m hosting the PDF on: it is *very* good. Before I discovered it I was using Bittorrent and Rapidshare to transfer large files which were inconvenient at best. Mediafire is, of course, free. It’s ad-supported, but that can be corrected for with a decent ad blocker like Adblock Plus. in terms of user-friendliness, the interface is beautifully animated (whether that’s good or not I’ll leave you to decide) and clear to use, and the site is extremely fast. It offers unlimited storage, unlimited up/down traffic, unlimited bandwidth, and features no annoying countdown like Rapidshare or Megauploads before free users can start downloading. The only limitations are the lack of hotlinking and 100MB file size limit for free users.

Summary for the sake of clarity:

Awesomeness
1. The interface is beautifully animated (whether that’s good or not I’ll leave you to decide) and clear to use
2. Site runs extremely fast
3. Unlimited storage
4. Unlimited up/down traffic
5. Unlimited Bandwidth
6. It features no annoying countdown like Rapidshare or Megauploads before free users can start downloading

Limitations
1. The site is ad-supported, but that can be corrected for with a decent ad blocker like Adblock Plus
2. No hotlinking
3. 100MB file size limit

That’s it folks, those are my recommendations for the day: don’t be fooled by hoaxes and use Mediafire ;)

๏̯͡๏﴿


Snail Mail

September 2, 2008

I was required recently to write to my sponsor after having attained an Arkwright scholarship, and while going through the nowadays almost unfamiliar and alien motions of printing a word-processed document, enclosing it in a brown envelope, handwriting a destination and applying a stamp, in order for a recipient to open the envelope and move information from that sheet of paper into their consciousness, I wondered how anybody could still use this relatively expensive, time-consuming, inefficient and slow process for actual communication of raw data, particularly plain-text messages and linked information. Most of the steps seem so unnecessary when compared with the capabilities of modern technology: so much paper is wasted on envelopes which serve only to enclose the information being sent; so many man hours are taken up sorting mail and delivering it *physically* to destinations when it can be transferred painlessly and electronically through the network of cables which is our internet; and so much effort is expended packaging up and ripping open mail when it can be done at the click of a button.

If the point is to convey an idea or data, such as a reminder to a friend about an event, email is infinitely superior. It’s far more reliable than snail mail, especially if you have to rely on Royal Mail; it is geared towards delivering the message as fast as possible even to the extent of splitting the message into parts and sending them separate ways, hence you don’t need to wait several days for your recipient to receive your message; and of course it’s (for most people) completely free. Plus it has functionality for interactivity – mail clients provide the recipient with a ‘reply’ button rather than simply a reply destination which must be reproduced on paper, and linked / referenced information is much enhanced (contrast hyperlinks with ISBN numbers or references to publications).

Don’t get me wrong: I’m not saying snail mail is at all useless; quite the contrary as I believe at times it can be the only appropriate way of doing something. To cite an example of such occasions, the letter to my sponsor, in my opinion, was written not really to communicate any specific data but to, in a rather subtle way, impress and leave a good impression. I was requested to introduce myself and include my GCSE results, the ultimate aim of which, surely in this case, being to leave some good impression to stimulate a response and hopefully pave the way for a good sponsor-student relationship. Email’s optimisation for speed is therefore unlikely to be appropriate on this occasion since it may possibly give the impression that communication with my sponsor is so unimportant that I’m trying to spend as little time on it as I can – hardly a good impression. A posted letter however gives the impression that time (and money for the stamp) has been put into communication and therefore that this said communication must be of high importance to me. Letters are also obviously tangible and therefore give me a more solid existence on the side of the recipient, complete with a personal touch – a signature – to prove my existence as a person. Don’t forget also that presentation is generally vastly easier to manipulate in mail since it’s a very literally WYSIWIG situation, while email relies on the recipient’s mail client’s settings and preferences; hence things like layout can be conceived with much more confidence in fidelity of reproduction at the recipient’s end than email.

However having said that, email seems such a huge step forwards that it makes me wonder whether, other than for instances in which communication is less about getting text data from A to B than about sending a specific message or impression (or for legal purposes which involve tangible signatures), people who know how to use email still actually use snail mail to communicate data.