Twenty years ago, there was only one web browser and it was actually called the “World Wide Web” browser. There was only one search engine and its name was Archie. About that same time I remember reading about the research team at the Cambridge University’s computer lab where they had a non-computer problem to solve – the department coffee pot was always empty when they wanted a cup.

Being computer science geeks, they of course, found a computer science solution to the problem – rig up a camera and network it so they could always see when the coffee pot was full. That way they could make sure there was going to be coffee in the pot before they made the journey down the hall to fill a cup. This is how the first web cam was born.

What does this have to do with email? When I was thinking of radical, esoteric ways to show how email can be used to automate external processes, guess what I thought of first? Yes, that’s right – coffee. In practical terms, my coffee pot is a flight of stairs away and, like the computer geeks at Cambridge, I too would like to know that there is actually coffee in it before I make the trek. So let’s do this: let’s create a message-driven workflow that will bring some certainty and clarity to the coffee situation in my office.

Getting started:

What we need to make this work is an understanding of the Lua language – don’t worry, I’ll walk you through it. One of the things the Momentum software is very good at is processing mail – accepting messages, doing something with them, and then responding to / delivering messages. It is the “do something” part that we’re going to concentrate on here. In this case we are going to use Momentum’s embedded Lua script engine to check the incoming mail and read the subject line. If the subject line says “Show My Coffee Pot” then we want Momentum to do several things: a) get the current image from my “coffee cam” b) generate a reply email to the sender with c) an image of the coffee pot in it. The web cam watching the coffee pot captures an image every 30 seconds and saves it as a file on the server, so we can just attach that file to the mail and it will always be the current image.

Here’s the Lua script that will enable Momentum to perform our coffee pot check:

— ############################################### —

— load Message Systems helper extensions

require(“msys.core”)

require(‘msys.extended.message’);

 

local mod = {};

 

function mod:validate_data(msg, str, accept, vctx)

— define the variable tables we will need for the message components

local ctx = { ec_message = msg };

local headers = {};

local pparts = {};

local attachments = {};

local subject = msg:header(“subject”);

 

if string.lower(subject[1]) == “show my coffee pot” then

— create a message container and define mailfrom and rcptto

local imsg = msys.core.ec_message_new(now);

local imailfrom = “noreply@c1n1.trymsys.net”;

local ircptto = msg:mailfrom();

 

— define the headers and message parts

headers[“To”] = ircptto;

headers[“From”] = “noreply@c1n1.trymsys.net”;

headers[“Subject”] = “Current image from CoffeeCam”;

pparts[“text/plain; charset=utf8”] = “The CofeeCam image is attached.”;

pparts[“text/html”] = “<b>! CoffeeCam !</b> <br /> Latest image is attached.”;

local files1={};

files1[“type”] = “image/jpg”;

files1[“name”] = “coffee.jpg”;

— load the webcam image to the attachments table

local file_name = “/opt/msys/ecelerity/etc/conf/default/lua/coffee.jpg”;

local io = msys.core.io_wrapper_open(file_name, msys.core.O_RDONLY, 0666)

files1[“content”] = io;

files1[“disposition”] = “inline”;

attachments[1] = files1;

 

— build and send

imsg:build(headers, pparts, attachments);

imsg:inject(imailfrom, ircptto);

end

return msys.core.VALIDATE_CONT;

end

 

msys.registerModule(“coffee”, mod);

— ############################################### —

Toggle Comments »


The above script simply needs to be applied to a current version of Momentum and it will work. Don’t have Momentum? No worries – you can see the result in our demonstration system by sending an email to noreply@c1n1.trymsys.net with the subject “Show My Coffee Pot” and the system will send you back the last available image of the coffee pot. Please note that the script running on this demo system may not be here forever. If it is ever disabled, I will try to remember to update this blog.

So what does this prove? Well, admittedly, the coffee pot example is frivolous and not exactly something to base a business model on, but imagine what you can do in your business if you can enable other processes based on message activity. In this case, we automatically send an image back to an email address based on a matching subject line, but what if we send back an image from a security camera based on receiving an SMS and a security code? Or maybe we could generate an alert message to the system administrator if a particular set of key words were in the body of a message. How about automatically printing off a paper report summarizing mail activity for every 1 million messages delivered? Or getting your bank balance texted to you?

The uses for this kind of automation are endless, and any of the above scenarios would only require minor tweaks to the basic code above. If this sounds like something your business could leverage, I’d be happy to set up a meeting for you with the appropriate people at Message Systems.

(Editor’s note: Please note that Tom’s live coffee cam might not be online 24×7, but emailing to noreply@c1n1.trymsys.net should still return the latest image on the server as outlined above.)